[PATCH] D63182: [ELF][PPC64] Don't report "relocation refers to a discarded section" for .toc

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 12 00:13:40 PDT 2019


MaskRay marked an inline comment as done.
MaskRay added inline comments.


================
Comment at: ELF/Relocations.cpp:721
 
+  // clang/gcc PPC64 may emit a .rela.toc which references a switch table in a
+  // discarded .rodata/.text section. The .toc and the .rela.toc are incorrectly
----------------
ruiu wrote:
> Hmm, has the compiler bug fixed? At least someone needs to fix this so that the compilers don't emit wrong code.
Not yet.. Latest clang and powerpc64le gcc 6 (available on goldbolt.org) have the bug. You can find a reference from .toc to a local label in .rodata.blah (clang) or .text.blah (clang). The reference is a section relative relocation.

```
void puts(const char *);

struct A {
  void foo(int a) {
    switch (a) {
    case 0: puts("0"); break;
    case 1: puts("1"); puts("1"); break;
    case 2: puts("2"); break;
    case 3: puts("3"); puts("4"); break;
    case 4: puts("4"); break;
    case 5: puts("5"); puts("5"); break;
    case 6: puts("6"); break;
    }
  }
  int a;
};

void foo(A x) {
  x.foo(x.a);
}
```


Repository:
  rLLD LLVM Linker

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

https://reviews.llvm.org/D63182





More information about the llvm-commits mailing list