Index: lld/ELF/Relocations.cpp =================================================================== --- lld/ELF/Relocations.cpp +++ lld/ELF/Relocations.cpp @@ -962,8 +962,15 @@ // PPC32 .got2 is similar but cannot be fixed. Multiple .got2 is infeasible // because .LC0-.LTOC is not representable if the two labels are in different // .got2 + // With basic block sections, there could be a relocation from the + // .gcc_except_table to a non-entry basic block section in a function. If that + // function is a COMDAT and the kept instance of the function does not have + // this section, then there could be a relocation to a discarded section. + // This is not wrong as the gcc_except_table is not part of the COMDAT group + // and can be safely ignored. if (cast(sym).discardedSecIdx != 0 && - (sec.name == ".got2" || sec.name == ".toc")) + (sec.name == ".got2" || sec.name == ".toc" || + sec.name == ".gcc_except_table")) return false; bool isWarning = Index: lld/test/ELF/x86-64-bbsection-gcc_except_table-reloc-discarded-section.s =================================================================== --- /dev/null +++ lld/test/ELF/x86-64-bbsection-gcc_except_table-reloc-discarded-section.s @@ -0,0 +1,39 @@ +# This test checks that the relocation from the .gcc_except_table to the comdat +# section .text._Z3foov._Z3foov.1 is not reported as a warning when that comdat +# copy is discarded. + +# REQUIRES: x86 +# RUN: split-file %s %t.split +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t.split/foo.s -o %t.split/foo.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t.split/bar.s -o %t.split/bar.o +# RUN: ld.lld %t.split/bar.o %t.split/foo.o -o %t + +//--- foo.s + .section .text.main,"ax",@progbits + .globl main # -- Begin function main + .p2align 4, 0x90 + .type main,@function +main: # @main + retq + .section .text._Z3foov,"axG",@progbits,_Z3foov,comdat + .weak _Z3foov # -- Begin function _Z3foov + .p2align 4, 0x90 + .type _Z3foov,@function +_Z3foov: # @_Z3foov + .section .text._Z3foov._Z3foov.1,"axG",@progbits,_Z3foov,comdat +_Z3foov.1: + .section .gcc_except_table,"a",@progbits + .p2align 2 +GCC_except_table2: +.Lexception0: + .byte 0 # @LPStart Encoding = absptr + .quad _Z3foov.1 + .byte 3 # @TType Encoding = udata4 + + +//--- bar.s + .section .text._Z3foov,"axG",@progbits,_Z3foov,comdat + .weak _Z3foov # -- Begin function _Z3foov + .p2align 4, 0x90 + .type _Z3foov,@function +_Z3foov: # @_Z3foov