How to run executable without specific CPU flags?

1

2

I'd like to test the behavior of an Linux ELF executable on a processor that doesn't have some CPU flags such as aes and sse2 given a processor that has those flags. What is the simplest way to emulate the absence of specific flags?

I suppose that, in the worst case, I can spin up a VM emulating a real-world processor that doesn't have those flags but maybe there is a simpler and more generic way. That would be useful for continuous integration, for instance.

bbc

Posted 2017-10-17T11:44:10.273

Reputation: 133

With virtualization you usually can not select the kind of CPU. The easiest would be to use compile flags. – Seth – 2017-10-17T12:27:22.910

Actually, some virtualization platforms like qemu let you do that. Regarding compile flags, they are out of scope here because the point is making sure the same binary behaves well on different processors. – bbc – 2018-04-10T09:30:23.150

Interesting to know. So you already have a solution (qemu)? But even with that you will have to take into account that actual emulation of other architectures will have a performance impact. Just like the exposure of features. What are you actually interested in testing? Why do you expect the program to behave differently? – Seth – 2018-04-11T08:36:13.287

I don't have a solution at hand, unfortunately. My program should use AES instructions if available and else fall back to a software implementation. The relevant flag is aes (for instance, in /proc/cpuinfo on Linux). – bbc – 2018-04-11T09:30:41.523

The AES instruction set goes back to 2008 with the first CPUs supporting it in 2010 it seems. If you don't want to setup qemu and don't want to use compile flags the easiest is likely to find an older system. If you do have separate paths for each case just test them separately and assume that you check works (after all it works to detect that the extension is available). It might also be possible to do something with seccomp but I'm really not sure that works/would actually be possible but it might be worth a look though more syscall focus

– Seth – 2018-04-11T10:29:43.963

No answers