$ gcc/xgcc -Bgcc/ -O2 -flto -flto-partition=none -fuse-linker-plugin -fno-fat-lto-objects -c -m32 -o c_lto_20090210_0.o ../gcc/testsuite/gcc.dg/lto/20090210_0.c
$ gcc/xgcc -Bgcc/ -O2 -flto -flto-partition=none -fuse-linker-plugin -fno-fat-lto-objects -fPIC -c -m32 -o c_lto_20090210_1.o ../gcc/testsuite/gcc.dg/lto/20090210_1.c
$ gcc/xgcc -Bgcc/ c_lto_20090210_0.o c_lto_20090210_1.o -O2 -flto -flto-partition=none -fuse-linker-plugin -fno-fat-lto-objects -m32 -o gcc-dg-lto-20090210-11.exe -save-temps
c_lto_20090210_0.s: Assembler messages:
c_lto_20090210_0.s:30: Error: syntax error; end of line, expected `('
lto-wrapper: fatal error: gcc/xgcc returned 1 exit status
/usr/powerpc64-suse-linux/bin/ld: lto-wrapper failed
collect2: error: ld returned 1 exit status
$ tail -n +30 c_lto_20090210_0.s | head -n 1
4c4a180dae54e5a879c76015b3ed181283190872 is the first bad commit
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@230915 138bc75d-0d04-0410-961f-82ee72b054a4
That looks like (latent?) bug in the target asm output - we should not produce invalid asm based on visibility changes. I will see if I can reproduce it on gcc compile farm.
Confirmed. Also the -O0 variant of this test. I had a look at assembly output and see lines like
This comes from rs6000_emit_load_toc_table use of toc_label_name which appears to be all-zero. toc_label_name is supposed to be set in rs6000_option_override_internal, but apparently isn't because when rs6000_option_override_internal runs, TARGET_TOC is not true. Making the initialisation unconditional isn't enough to cure the problem as that leads to linker errors about an undefined reference to ".LCTOC1". That is because code to set .LCTOC1 isn't being emitted from rs6000_elf_output_toc_section_asm_op.
I haven't verified this, but I'd guess that is because rs6000_file_start doesn't see flag_pic == 2, and therefore doesn't call switch_to_section (toc_section).
Notice that c_lto_20090210_0.o does *not* have -fPIC, while c_lto_20090210_1.o does.
OK, this looks more like target issue so I am changing component. flag_pic is a global option and it is merged by the lto wrapper and corrected based on the linker output. Because static executable is built, flag_pic should be 0.
Targets must be ready for -fPIC being different at compile time and link time and ought to honor the link time setting...
Created attachment 37475 [details]
So what about this untested patch? ASM_GENERATE_INTERNAL_LABEL doesn't look to be too expensive to do unconditionally once, and for GC sanity it needs to go through ggc_strdup anyway (it is invalid to refer to non-GC allocated strings in GTY const char * fields that are not skipped by GC).
Unconditionally generating toc_label_name is okay with me, but I thought that Alan commented it was not sufficient in Comment #2.
Date: Tue Jan 26 19:53:37 2016
New Revision: 232844
* config/rs6000/rs6000.c (rs6000_option_override_internal): Initialize
(rs6000_emit_load_toc_table): Call ggc_strdup on toc_label_name for
SYMBOL_REF string. Use toc_label_name instead of constructing
(rs6000_elf_declare_function_name): Use toc_label_name instead of
Seems like powerpc* has lots of other issues related to mixing pic and non-pic code. E.g.
__attribute__((optimize ("PIC"))) int
seems to ICE due to endless recursion with -O2 -m32 (every force_reg causes another force_reg, at least in x86_64-linux -> powerpc64-linux cross).
(In reply to Jakub Jelinek from comment #7)
> seems to ICE due to endless recursion with -O2 -m32 (every force_reg causes
> another force_reg, at least in x86_64-linux -> powerpc64-linux cross).
I see a similar failure on a native compile too.
For the testcase in comment #7, global_options are inconsistent (*) and wrong when compiling foo. I see flag_pic == 2 there??
(*) In particular, TARGET_RELOCATABLE and flag_pic don't agree. See config/rs6000/sysv4.h SUBTARGET_OVERRIDE_OPTIONS. flag_pic == 2 ought to mean TARGET_RELOCATABLE is true, but TARGET_RELOCATABLE is false. This combination is not recognized in rs6000_emit_move.
I guess rs6000 needs to implement targetm.override_options_after_change() if we're to keep flag_pic and TARGET_RELOCATABLE consistent.
Making the toc initialization in rs6000_file_start not depend on flag_pic, ie. use
if (DEFAULT_ABI != ABI_DARWIN)
and applying Jakub's option handling fix for pr61925 to the rs6000 backend, and fixing a testcase seems to cure this problem.
However, I'll note that the comment #7 testcase fails to compile foo non-PIC, even on x86 -m32. Looks like flag_pic and a whole bunch of other flags are not saved/restored around attribute((optimize())).
Should we add an assert somewhere to ensure that flag_pic and TARGET_RELOCATABLE are consistent?
Date: Tue Feb 2 00:01:16 2016
New Revision: 233061
[RS6000] ABI_V4 init of toc section
Since 4c4a180d lto has turned off flag_pic when linking a fixed
position executable. So flag_pic is zero in rs6000_file_start.
However, when we get to actually emitting code, flag_pic may be on
again. This results in undefined references to ".LCTOC1".
* config/rs6000/rs6000.c (need_toc_init): New var, set it
whenever toc_label_name used.
(rs6000_file_start): Don't set up toc section here,
(rs6000_output_function_epilogue): do so here instead,
(rs6000_xcoff_file_start): and here.
* config/rs6000/rs6000.md (load_toc_aix_si): Set need_toc_init.
Fixed with workaround. https://gcc.gnu.org/ml/gcc-patches/2016-02/msg00002.html queued for gcc-7 and 6.1.
Date: Thu May 5 00:07:27 2016
New Revision: 235914
For ABI_V4, -mrelocatable and -fPIC both generate position independent
code, with some extra "fixup" output for -mrelocatable. The
similarity of these two options has led to the situation where the
sysv4.h SUBTARGET_OVERRIDE_OPTIONS sets flag_pic on seeing
-mrelocatable, and sets TARGET_RELOCATABLE on seeing -fPIC. That
prevents LTO from properly optimizing position dependent executables,
because the mutual dependence of the flags and the fact that LTO
streaming records the state of rs6000_isa_flags, result in flag_pic
being set when it shouldn't be.
So, don't set TARGET_RELOCATABLE when -fPIC. Places that currently
test TARGET_RELOCATABLE can instead test
TARGET_RELOCATABLE || (DEFAULT_ABI == ABI_V4 && flag_pic > 1)
or since TARGET_RELOCATABLE can only be enabled when ABI_V4,
DEFAULT_ABI == ABI_V4 && (TARGET_RELOCATABLE || flag_pic > 1).
Also, since flag_pic is set by -mrelocatable, a number of places that
currently test TARGET_RELOCATABLE can be simplified. I also made
-mrelocatable set TARGET_NO_FP_IN_TOC, allowing TARGET_RELOCATABLE to
be removed from ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. Reducing occurrences
of TARGET_RELOCATABLE is a good thing.
* config/rs6000/sysv4.h (SUBTARGET_OVERRIDE_OPTIONS): Don't
set OPTION_MASK_RELOCATABLE when flag_pic == 2. Set
TARGET_NO_FP_IN_TOC for -mrelocatable.
(MINIMAL_TOC_SECTION_ASM_OP): Remove redundant
* config/rs6000/linux64.h (MINIMAL_TOC_SECTION_ASM_OP): Likewise.
* config/rs6000/freebsd64.h (MINIMAL_TOC_SECTION_ASM_OP): Likewise.
* config/rs6000/predicates.md (easy_fp_constant): Likewise.
* config/rs6000/rs6000.c (rs6000_elf_output_toc_section_asm_op):
(rs6000_assemble_integer): Update TARGET_RELOCATABLE test.
* config/rs6000/rs6000.md (load_toc_aix_di): Likewise.
* config/rs6000/rs6000.h (MASK_RELOCATABLE, MASK_MINIMAL_TOC):