On Wed, Oct 15, 2014 at 10:18 AM, Ilya Palachev <i.palac...@samsung.com> wrote: > On 15.10.2014 10:59, Jakub Jelinek wrote: >> >> On Tue, Oct 14, 2014 at 08:39:40PM +0400, Ilya Palachev wrote: >>> >>> Attached patch fixes PR lto/61048 - >>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61048 >> >> >> Given that the patch just replaces an ICE with a necessary link failure, >> I'd say >> it is done at the wrong place, instead during the LTO option handling you >> should error out if there are incompatibilities in -fsanitize options >> (any object compiled with flag_sanitize & SANITIZE_USER_ADDRESS, but >> link done without that, ditto for SANITIZE_KERNEL_ADDRESS, >> SANITIZE_THREAD. >> And finally if flag_sanitize & (SANITIZE_UNDEFINED | SANITIZE_NONDEFALT) >> is non-zero but during linking it is zero (it doesn't really matter which >> exact undefined sanitization options are used at what time). > > > As I understand you suggest that the compiler should: > - Write compiler options with which the object file was compiled to the ELF > format in a special section. > - Read these sections during the linking command > - Compare collected sets of options with options that were set at linking > command. > ? > > Does compiler have any opportunity to save the set of options with which the > object file was compiled inside some special ELF section? For LTO they the > special section ".gnu.lto_.opts" is used. But not all compiler options are > written to it: > > $ gcc -fsanitize=address -c test.cpp -o test.o -flto > $ objdump --full-contents --section=.gnu.lto_.opts test.o > > test.o: file format elf64-x86-64 > > Contents of section .gnu.lto_.opts: > 0000 272d6665 78636570 74696f6e 73272027 '-fexceptions' ' > 0010 2d666d61 74682d65 72726e6f 2720272d -fmath-errno' '- > 0020 66736967 6e65642d 7a65726f 73272027 fsigned-zeros' ' > 0030 2d667472 61707069 6e672d6d 61746827 -ftrapping-math' > 0040 20272d66 6e6f2d74 72617076 2720272d '-fno-trapv' '- > 0050 666e6f2d 73747269 63742d6f 76657266 fno-strict-overf > 0060 6c6f7727 20272d6d 74756e65 3d67656e low' '-mtune=gen > 0070 65726963 2720272d 6d617263 683d7838 eric' '-march=x8 > 0080 362d3634 2720272d 666c746f 2700 6-64' '-flto'. > > As you can see there is no "-fsanitize" option here. Only options that are > handled in function lto_write_options in lto-opts.c are written there. > > Does gcc has an opportunity to write something like ELF section ".gnu.opts" > to save all compiler options with which the object file was compiled? > Or we need to introduce such section? Or anything else?
You need to handle them in lto-opts.c and output them to the existing option section. Not sure why they don't appear there already - ah, because of /* Also drop all options that are handled by the driver as well, which includes things like -o and -v or -fhelp for example. We do not need those. Also drop all diagnostic options. */ if (cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING)) continue; and -fsanitize= being marked as Driver. Looks like we have to drop things explicitely here given that -o is also Common Driver. Or simply have if (cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING)) switch (option->opt_index) { case OPT_fsanitize_: break; default: continue; } instead. Richard. >> >> BTW, in your patches please watch formatting, you didn't use space before >> (. > > > Sorry for that. I'll check it in further patches. > >> >> Jakub >> >