[llvm-bugs] [Bug 46675] Better handle relocation in .gcc_except_table to discarded sections.

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jul 12 11:54:31 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46675

Fangrui Song <i at maskray.me> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |i at maskray.me
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED

--- Comment #1 from Fangrui Song <i at maskray.me> ---
tl;dr I think clang -target riscv64 emits invalid .gcc_except_table

/// I should have asked you to provide a C++ file as well.. Nevermind, I have
figured out a simple reproduce
// a.cc
inline int comdat() {
  try { throw 1; }
  catch (int) { return 1; }
  return 0;
}
int main() { return comdat(); }
// b.cc
inline int comdat() {
  try { throw 1; }
  catch (int) { return 1; }
  return 0;
}
int foo() { return comdat(); }

clang++ -target riscv64-linux -c a.cc b.cc -fPIC
ld.lld -shared a.o b.o => ld.lld: error: relocation refers to a symbol in a
discarded section:


b.o has a relocation in .gcc_except_table referencing a STB_LOCAL STT_SECTION
symbol. The STT_SECTION's section is in a section group.

Relocation section '.rela.gcc_except_table' at offset 0x7a0 contains 16
entries:
    Offset             Info             Type               Symbol's Value 
Symbol's Name + Addend
0000000000000005  0000000800000023 R_RISCV_ADD32          0000000000000000
<null> + 0
0000000000000005  0000000800000027 R_RISCV_SUB32          0000000000000000
<null> + 0

According to the ELF spec, this is invalid:

> 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.


.eh_frame/ppc64 .toc/ppc32 .got2 are notable violations that we have to work
around them. However, .gcc_except_table is apparently fixable and GCC does
place .gcc_except_table._Z6comdatv in a section group

% riscv64-linux-gnu-g++ -c a.cc b.cc -fPIC
% readelf -WS b.o
...
  [ 8] .text._Z6comdatv  PROGBITS        0000000000000000 00008a 000074 00 AXG 
0   0  2                                                              
  [ 9] .rela.text._Z6comdatv RELA            0000000000000000 000708 000150 18 
IG 20   8  8                                                          
  [10] .gcc_except_table._Z6comdatv PROGBITS        0000000000000000 000100
000028 00  AG  0   0  4                                                   
  [11] .rela.gcc_except_table._Z6comdatv RELA            0000000000000000
000858 000120 18  IG 20  10  8


I think clang should follow suit. I'll mark this as invalid and try fixing
clang.

----

(1) As you may have seen, LLD errors:

error: a.cc:(.text+0x0): relocation R_RISCV_ALIGN requires unimplemented linker
relaxation; recompile with -mno-relax

R_RISCV_ALIGN/R_RISCV_RELAX support are very complex.

(2) riscv64-linux-gnu-g++ -c a.cc b.cc -fPIC; ld.lld -shared a.o b.o segfaults
because it expects relocations in .eh_frame to have non-decreasing r_offset
This is not true for GCC. I'll need to investigate this as well

Relocation section '.rela.eh_frame' at offset 0x9a8 contains 10 entries:
    Offset             Info             Type               Symbol's Value 
Symbol's Name + Addend
0000000000000013  0000002100000039 R_RISCV_32_PCREL       0000000000000000
DW.ref.__gxx_personality_v0 + 0
0000000000000024  0000000600000039 R_RISCV_32_PCREL       0000000000000000 .L0 
+ 0
0000000000000028  0000000900000023 R_RISCV_ADD32          0000000000000074 .L0 
+ 0
0000000000000028  0000000600000027 R_RISCV_SUB32          0000000000000000 .L0 
+ 0
000000000000002d  0000001a00000039 R_RISCV_32_PCREL       0000000000000000
.LLSDA0 + 0
0000000000000068  0000000c00000039 R_RISCV_32_PCREL       0000000000000000 .L0 
+ 0
000000000000006c  0000000d00000023 R_RISCV_ADD32          0000000000000020 .L0 
+ 0
000000000000006c  0000000c00000027 R_RISCV_SUB32          0000000000000000 .L0 
+ 0
0000000000000040  0000000800000036 R_RISCV_SET8           000000000000006c .L0 
+ 0
0000000000000040  0000000700000025 R_RISCV_SUB8           000000000000000a .L0 
+ 0

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200712/9977d8ad/attachment-0001.html>


More information about the llvm-bugs mailing list