llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.32k stars 12.12k forks source link

Darwin -fsanitize=cfi -flto=thin causes raw bitcode to be emitted, instead of Mach-O-wrapped bitcode #32088

Open ahmedbougacha opened 7 years ago

ahmedbougacha commented 7 years ago
Bugzilla Link 32741
Version unspecified
OS All
CC @pcc

Extended Description

r301016 enabled CFI tests using ThinLTO on Darwin, but those are failing:

ld: warning: ignoring file /var/folders/09/r4vw4v8n5kb67jl66zvlbljw0000gn/T/lit_tmp_j2NEGY/nvcall-1477f4.o, file was built for unsupported file format ( 0x42 0x43 0xC0 0xDE 0x35 0x14 0x00 0x00 0x05 0x00 0x00 0x00 0x62 0x0C 0x30 0x24 ) which is not the architecture being linked (x86_64): /var/folders/09/r4vw4v8n5kb67jl66zvlbljw0000gn/T/lit_tmp_j2NEGY/nvcall-1477f4.o Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64

http://green.lab.llvm.org/green/job/clang-stage1-configure-RA_check/30480/consoleFull#-121919748349ba4694-19c4-4d7e-bec5-911270d8a58c

It seems that -fsanitize=cfi somehow causes -flto=thin to emit bitcode instead of mach-o:

$ ./bin/clang -flto=thin -fvisibility=hidden -fsanitize=cfi /tmp/t.cpp -c && file t.o t.o: LLVM IR bitcode $ ./bin/clang -flto=thin -fvisibility=hidden /tmp/t.cpp -c && file t.o t.o: LLVM bitcode, wrapper x86_64

And it seems that ld64 doesn't accept raw bitcode.

pcc commented 7 years ago

...on Darwin.

pcc commented 7 years ago

This has no hope of working until ld64 is changed to use the resolution-based LTO API. Until then, we will need to change the clang driver to prevent the use of -flto=thin with -fsanitize=cfi (and -fwhole-program-vtables).