[PATCH] D75416: [PowerPC][ELF] Place .toc in the same COMDAT group as the target object

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 1 21:42:11 PST 2020


MaskRay abandoned this revision.
MaskRay added a comment.

This is a fundamental problem of .toc . It cannot be fixed, oh, well, without some ELF extensions.

For @Bdragon28's reproduce file,

A .text (not in a section group) references `foo` defined in .data.rel.ro.foo (in a section group) via .toc .
This patch emits `.section .toc,"aGw",foo,comdat`.
When `.data.rel.ro.foo` and the `.toc` are discarded due to the section group rule, the relocation from `.text` to the `.toc` becomes dangling.

> A symbol table entry with STB_LOCAL binding that is defined relative to one of a group's sections, and that is contained in a symbol table section that is not part of the group, must be discarded if the group members are discarded. References to this symbol table entry from outside the group are not allowed.

One thought is to change the .toc reference to a STB_GLOBAL, say, `addis 3,2,foo.toc at toc@ha; ld 4, foo.toc at toc@l(3); .section .toc,"aGw", at progbits,foo,comdat; .globl foo.toc; foo.toc: .tc foo[TC],foo`.
Say, both a.o and b.o have the code sequence above. If `a.o(.toc)` survives, the symbolic reference `add 3,2,foo.toc at toc@ha` from b.o will bind to `a.o(.toc)` (like an external reference).

Unfortunately, there will be another problem. `foo.toc` will be left in .symtab and .dynsym . If we set the visibility of `foo.toc` to STB_HIDDEN or STB_INTERNAL, `foo.toc` will be omitted from .dynsym, but we cannot omit from .symtab.
Unless we extend ELF and say STB_INTERNAL symbols are omitted from .symtab.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75416





More information about the llvm-commits mailing list