zetzit / zz

πŸΊπŸ™ ZetZ a zymbolic verifier and tranzpiler to bare metal C
MIT License
1.6k stars 52 forks source link

Error when setting CC=gcc #35

Closed DestyNova closed 4 years ago

DestyNova commented 4 years ago

Apologies if this is just user error; I've just found zz and wanted to try running it with GCC.

I can force Clang to be used (which I guess is the default output anyway) by specifying the environment variable CC=clang. However, when I set CC to gcc, this happens:

~/code/zz/zz/examples/switch $ CC=gcc cargo run build --release
...
done emitting                                                                                                                                                            
gcc: error: : No such file or directory
[ERROR] gcc  -fPIC -I . -I -fvisibility=hidden -O03 -flto -fomit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables -fno-unwind-tables -Werror=implicit-function-declaration -Werror=incompatible-pointer-types -Werror=return-type -Wpedantic -Wall -Wno-unused-function -Wno-parentheses-equality -Wno-flexible-array-extensions -Wno-gnu-variable-sized-type-not-at-end -Werror=pointer-sign -Werror=int-to-pointer-cast -c target/release/zz/switch_main.c -o ./target/release/zz/_switch_main_b62f26286d75fddaf1d47701e6be86f8.o
failed [Exe] switch   

However, if I copy/paste the GCC command from the output, it builds the .o file with no problems.

I added in some debugging but can't really see what the problem is. It dies at this part of src/make.rs:

            if step.is_dirty() {
                debug!("{} {:?}", self.cc, step.args);
                let status = Command::new(&self.cc)
                    .env("AFL_USE_ASAN", "1")
                    .args(&step.args)
                    .status()
                    .expect("failed to execute cc");
                if !status.success() {
                    error!("cc: [{}] args: [{}]", self.cc, step.args.join(" "));
                    ABORT.store(true, Ordering::Relaxed);
                }
            }
DestyNova commented 4 years ago

Oh, I figured it out -- I actually need the CXX environment variable, not CC. I'm not really sure why, but it works.

aep commented 4 years ago

thanks for the report!

hmm not sure what's happening there. CXX is only really used when the project has std='c++' set. either way the error message isn't helpful.

could you post the rest of your environment variables? also the project's zz.toml

DestyNova commented 4 years ago

Sure! It's the switch project in the examples directory.

I'm not sure which env vars might be relevant, so here's all of them. There's a lot; I've been running this laptop for about 7 years:

<snip env spam that didn't shed light on the problem>

The only thing I can think of that might affect it is the order of stuff in my PATH.

DestyNova commented 4 years ago

Incidentally, I noticed that whether I build with Clang or GCC, the output binary (even for just a hello world program) is about 1.3 megabytes in size (in Ubuntu). When I ran it on a Macbook it seemed to produce much smaller executables. objdump printed lots of output with "sanitizer" and "interceptor" etc. Is this just to do with how big libc is on modern systems?

aep commented 4 years ago

that's the address sanitizer build into default test binaries. you want to build --release or --debug for impressive sizes :)

aep commented 4 years ago

i can't find any problems in your env unless there's a broken gcc hiding in your PATH, but you would have probably noticed that earlier :D

could you run with strace -f please?

DestyNova commented 4 years ago

I seem to get the same binary even if I use cargo run build --release... am I putting the arg in the wrong place?

Here's the gzipped strace output -- I see some locale stuff happening soon before the error, but not sure how to connect the dots :thinking:

DestyNova commented 4 years ago

Oh, derp. Just noticed that using CXX=gcc is actually ignored, since this shows up in the build output:

clang "target/test/zz/switch_main.c"

That's also with zz --release.

DestyNova commented 4 years ago

Oh, this part looks suspicious:

[pid 22010] execve("/usr/bin/x86_64-linux-gnu-gcc-9", ["/usr/bin/x86_64-linux-gnu-gcc-9", "", "-fPIC", "-I", ".", "-I", "-fvisibility=hidden", "-g", "-fstack-protector-strong", "-fsanitize=address", "-Werror=implicit-function-declar"..., "-Werror=incompatible-pointer-typ"..., "-Werror=return-type", "-Wpedantic", "-Wall", "-Wno-unused-function", "-Wno-parentheses-equality", "-Wno-flexible-array-extensions", "-Wno-gnu-variable-sized-type-not"..., "-Werror=pointer-sign", "-Werror=int-to-pointer-cast", "-c", "target/test/zz/switch_main.c", "-o", "./target/test/zz/_switch_main_80"...], 0x55e0eb8d93c0 /* 105 vars */ <unfinished ...>

Note the argv params: ["/usr/bin/x86_64-linux-gnu-gcc-9", "", ...

I think, maybe as a result of a stray space at the beginning of the arguments, gcc interprets the input filename as an empty string.

DestyNova commented 4 years ago

Okay -- I traced it back to the cflags value of the Make struct being initialised to the one element vector [""], so later gcc receives an empty string as the first argument. I'm guessing Clang doesn't care about this.

If I use CFLAGS="-O2" then we pass this part, and it crashes at a later step (maybe during linking) for the same reason, except with LDFLAGS. So I set LDFLAGS="-v" and the build works.

I might try to make a patch to make the default cflags and ldflags be an empty Vec. :grinning:

DestyNova commented 4 years ago

Fixed. Will fork and send a PR now.

DestyNova commented 4 years ago

Also, I managed to get the --release argument to work. Not sure why it didn't before, but now it seems OK!

BTW, is there a Gitter or some other place to ask silly questions without cluttering the issue tracker?

aep commented 4 years ago

am I putting the arg in the wrong place?

yes :). it's a zz arg, not cargo arg. for cargo to pass it on you use it like "cargo run -- --debug". zz has 3 build modes: test debug release. the test mode adds a ton of sanitizers which check for bugs at runtime that can't be caught at compile time yet (asan, ubsan). debug is C-standard -O0 -g and release -O3

so later gcc receives an empty string as the first argument.

duh thanks

BTW, is there a Gitter

there's a reddit, but i don't think anyone uses it. might close again. opening bugs here for questions is totally fine, github has good search for other people to find it who might have the same question.

charles-l commented 4 years ago

I'm seeing a similar file not found error when CC=clang -- is clang not supported? I didn't see anything in the docs about it... gcc works fine in the meantime.

aep commented 4 years ago

@charles-l should work fine. Can you post althe output of strace -f zz build please?

charles-l commented 4 years ago

@aep Oh wow -- I'm a dolt. I didn't have clang installed on my system (I've reinstall linux on this box one too many times :P). Sorry for the superfluous bug report.

For future reference, if anyone else gets an error similar to:

comp [ ]  22 / 22 [==================================================] 100.00 % thread '<unnamed>' panicked at 'failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/make.rs:386:30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at 'failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }thread '', <unnamed>src/make.rs' panicked at ':failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }386', :src/make.rs30:
386:30
thread '<unnamed>' panicked at 'failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/make.rs:thread '386:<unnamed>30' panicked at '
failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/make.rs:386:30
thread '<unnamed>' panicked at 'failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/make.rs:386:30
thread '<unnamed>' panicked at 'failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/make.rs:386:30
thread '<unnamed>' panicked at 'failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/make.rs:386:30
thread '<unnamed>' panicked at 'failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/make.rs:386:30
thread '<unnamed>' panicked at 'failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/make.rs:386:30
thread '<unnamed>' panicked at 'failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/make.rs:386:30
thread '<unnamed>' panicked at 'failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/make.rs:386:30
thread '<unnamed>' panicked at 'failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/make.rs:386:30
thread '<unnamed>' panicked at 'failed to execute cc: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/make.rs:386:30

... double check that clang is installed.