[PATCH] D61070: [libFuzzer] Enable on i386

Jonathan Metzman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 29 15:20:00 PDT 2019


metzman marked an inline comment as done.
metzman added inline comments.


================
Comment at: compiler-rt/lib/fuzzer/CMakeLists.txt:128
+      set(EMULATION_ARGUMENT "")
+    endif()
     set(cxx_${arch}_merge_dir "${CMAKE_CURRENT_BINARY_DIR}/cxx_${arch}_merge.dir")
----------------
morehouse wrote:
> metzman wrote:
> > morehouse wrote:
> > > Why is this argument necessary?
> > Without it we get this error: `/usr/bin/ld: Relocatable linking with relocations from format elf32-i386 (/home/user/llvm-build/lib/clang/9.0.0/lib/linux/libclang_rt.fuzzer-i386.a(FuzzerCrossOver.cpp.o)) to format elf64-x86-64 (fuzzer.o) is not supported`
> > 
> > Interestingly, this has been a problem with libFuzzer before, see [[ https://forum.xda-developers.com/android/software-hacking/llvm-clang-dragontc-future-t3318386/page34 | here ]].
> The error sounds like we're trying to mix 32-bit and 64-bit.  So maybe we should address that instead?
> 
> I also notice that the documentation for some linkers (gold) say that `-m` is obsolete.
>The error sounds like we're trying to mix 32-bit and 64-bit.

I'm not sure this the case.

The command that causes this failure is
```
/usr/bin/ld --whole-archive /home/user/llvm-project/build-x862/lib/clang/9.0.0/lib/linux/libclang_rt.fuzzer-i386.a --no-whole-archive /home/user/llvm-project/build-x862/projects/compiler-rt/lib/fuzzer/libcxx_fuzzer_i386/lib/libc++.a -r -o fuzzer.o
```
Minimized:
```
/usr/bin/ld -r --whole-archive /home/user/llvm-project/build-x862/lib/clang/9.0.0/lib/linux/libclang_rt.fuzzer-i386.a -o fuzzer.o
```

But `/home/user/llvm-project/build-x862/lib/clang/9.0.0/lib/linux/libclang_rt.fuzzer-i386.a ` only contains 32 bit code afaict:

```
objdump -d /home/user/llvm-project/build-x862/lib/clang/9.0.0/lib/linux/libclang_rt.fuzzer_no_main-i386.a | grep "\.o"
FuzzerCrossOver.cpp.o:     file format elf32-i386
FuzzerDataFlowTrace.cpp.o:     file format elf32-i386
FuzzerDriver.cpp.o:     file format elf32-i386
FuzzerExtFunctionsDlsym.cpp.o:     file format elf32-i386
FuzzerExtFunctionsWeak.cpp.o:     file format elf32-i386
FuzzerExtFunctionsWindows.cpp.o:     file format elf32-i386
FuzzerExtraCounters.cpp.o:     file format elf32-i386
FuzzerFork.cpp.o:     file format elf32-i386
FuzzerIO.cpp.o:     file format elf32-i386
FuzzerIOPosix.cpp.o:     file format elf32-i386
FuzzerIOWindows.cpp.o:     file format elf32-i386
FuzzerLoop.cpp.o:     file format elf32-i386
FuzzerMerge.cpp.o:     file format elf32-i386
FuzzerMutate.cpp.o:     file format elf32-i386
FuzzerSHA1.cpp.o:     file format elf32-i386
FuzzerTracePC.cpp.o:     file format elf32-i386
FuzzerUtil.cpp.o:     file format elf32-i386
FuzzerUtilDarwin.cpp.o:     file format elf32-i386
FuzzerUtilFuchsia.cpp.o:     file format elf32-i386
FuzzerUtilLinux.cpp.o:     file format elf32-i386
FuzzerUtilPosix.cpp.o:     file format elf32-i386
FuzzerUtilWindows.cpp.o:     file format elf32-i386
```

gold and lld can run /usr/bin/ld.bfd -r --whole-archive ~/llvm-project/build-x862/lib/clang/9.0.0/lib/linux/libclang_rt.fuzzer-i386.a -o fuzzer.o just fine by the way.
When I run file on the output, it says:
```
fuzzer.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), with debug_info, not stripped
```
Which would be surprising if I actually was including 64 bit code.
I think this is just a bug/quirk in GNU ld that needs `-m elf_i386` to be solved.

You can verify ld needs this using this simple reproducer:
```
$ echo "int x() { return 0; }" > x.cc
$ g++ -m32 -c x.cc
$ ar qc x.a x.o
$ ld -r --whole-archive x.a -o x2.o
ld: Relocatable linking with relocations from format elf32-i386 (x.a(x.o)) to format elf64-x86-64 (x2.o) is not supported
```



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61070/new/

https://reviews.llvm.org/D61070





More information about the llvm-commits mailing list