Michal Jires <mji...@suse.cz> writes: > Check that must_remain_in_tu is partitioned correctly, and that > refereced_from_asm is not renamed. > > gcc/lto/ChangeLog: > > * lto-partition.cc (lto_1_to_1_map): must_remain_in_tu check. > (privatize_symbol_name_1): refereced_from_asm check.
I get this when trying out the patches: # LDFINAL vmlinux.o sh /var/tmp/portage/sys-kernel/gentoo-kernel-6.16.4/work/linux-6.16/scripts/gcc-ld -flinker-output=nolto-rel -flto=jobserver -flto-partition=1to1 -fwhole-program -m elf_x86_64 --compre ss-debug-sections=zlib -z noexecstack --no-warn-rwx-segments -r -o vmlinux.o --whole-archive vmlinux.a --no-whole-archive --start-group --end-group ; ./tools/objtool/objtool --hacks= jump_label --hacks=noinstr --ibt --orc --retpoline --rethunk --sls --static-call --uaccess --link vmlinux.o x86_64-pc-linux-gnu-gcc -nostdlib -flinker-output=nolto-rel -flto=jobserver -flto-partition=1to1 -fwhole-program -Wl,-m,elf_x86_64 -Wl,--compress-debug-sections=zlib -Wl,-z,noexecstack - Wl,--no-warn-rwx-segments -r -o vmlinux.o -Wl,--whole-archive vmlinux.a -Wl,--no-whole-archive -Wl,--start-group -Wl,--end-group lto1: fatal error: Tried to privatize symbol sp_mod_init. compilation terminated. lto-wrapper: fatal error: x86_64-pc-linux-gnu-gcc returned 1 exit status compilation terminated. I haven't tried to figure out why though. > --- > gcc/lto/lto-partition.cc | 43 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 43 insertions(+) > > diff --git a/gcc/lto/lto-partition.cc b/gcc/lto/lto-partition.cc > index b87ca440bc9..484a9ea9d94 100644 > --- a/gcc/lto/lto-partition.cc > +++ b/gcc/lto/lto-partition.cc > @@ -393,6 +393,42 @@ lto_1_to_1_map (void) > /* Order partitions by order of symbols because they are linked into binary > that way. */ > ltrans_partitions.qsort (cmp_partitions_order); > + > + /* Check that symbols with must_remain_in_tu are partitioned correctly. */ > + if (flag_checking) > + { > + unsigned partitions = ltrans_partitions.length (); > + for (unsigned i = 0; i < partitions ; i++) > + { > + ltrans_partition p = ltrans_partitions[i]; > + lto_symtab_encoder_iterator lsei; > + for (lsei = lsei_start_in_partition (p->encoder); > + !lsei_end_p (lsei); > + lsei_next_in_partition (&lsei)) > + { > + symtab_node *node = dyn_cast<symtab_node*> (lsei_node (lsei)); > + if (!node) > + continue; > + if (!node->must_remain_in_tu) > + continue; > + if (!lto_symtab_encoder_in_partition_p (p->encoder, node)) > + continue; > + if (node->asm_name ()[0] == '*') > + continue; > + if (!node->lto_file_data) > + continue; > + > + ltrans_partition *slot = pmap.get (node->lto_file_data); > + if (!slot || *(slot) != p) > + { > + const char* fname = node->lto_file_data->file_name; > + fatal_error (input_location, "Symbol %s from file %s" > + "cannot be in partition %s", > + node->asm_name (), fname, p->name); > + } > + } > + } > + } > } > > /* Creates partition with all toplevel assembly. > @@ -1691,6 +1727,13 @@ privatize_symbol_name_1 (symtab_node *node, tree decl) > if (must_not_rename (node, name0)) > return false; > > + if (node->referenced_from_asm) > + { > + /* Symbols referenced from asm should not change their name. */ > + fatal_error (input_location, "Tried to privatize symbol %s.", > + node->asm_name ()); > + } > + > const char *name = maybe_rewrite_identifier (name0); > unsigned &clone_number = lto_clone_numbers->get_or_insert (name); > symtab->change_decl_assembler_name (decl,