[PATCH] D52202: [ELF] Use the Repl point to avoid the segfault when using ICF
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 17 20:01:36 PDT 2018
phosek updated this revision to Diff 165891.
phosek added a comment.
Now also includes a reproducer.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D52202
Files:
lld/ELF/InputSection.cpp
lld/test/ELF/icf18.s
Index: lld/test/ELF/icf18.s
===================================================================
--- /dev/null
+++ lld/test/ELF/icf18.s
@@ -0,0 +1,49 @@
+# RUN: yaml2obj %s -o %t.o
+# RUN: ld.lld --icf=all --emit-relocs %t.o -o /dev/null --print-icf-sections 2>&1 | FileCheck %s
+
+# Checks that ICF with --emit-relocs doesn't crash.
+
+# CHECK: removing identical section
+# CHECK: (.text.bar)
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_FREEBSD
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .text.foo
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Content: "FFFFFFFFFFFFFFFF"
+ - Name: .text.bar
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Content: "FFFFFFFFFFFFFFFF"
+ - Name: .text.foo_test
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ - Name: .rela.text.foo_test
+ Type: SHT_RELA
+ Info: .text.foo_test
+ Relocations:
+ - Offset: 0x0000000000000000
+ Symbol: .text.foo
+ Type: R_X86_64_PLT32
+ - Offset: 0x0000000000000000
+ Symbol: .text.bar
+ Type: R_X86_64_PLT32
+Symbols:
+ Local:
+ - Name: .text.foo
+ Type: STT_SECTION
+ Section: .text.foo
+ - Name: .text.bar
+ Type: STT_SECTION
+ Section: .text.bar
+ Global:
+ - Name: _start
+ Type: STT_FUNC
+ Section: .text.foo_test
Index: lld/ELF/InputSection.cpp
===================================================================
--- lld/ELF/InputSection.cpp
+++ lld/ELF/InputSection.cpp
@@ -402,7 +402,7 @@
}
if (RelTy::IsRela)
- P->r_addend = Sym.getVA(Addend) - Section->getOutputSection()->Addr;
+ P->r_addend = Sym.getVA(Addend) - Section->Repl->getOutputSection()->Addr;
else if (Config->Relocatable)
Sec->Relocations.push_back({R_ABS, Type, Rel.r_offset, Addend, &Sym});
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52202.165891.patch
Type: text/x-patch
Size: 2221 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180918/145e8cf9/attachment.bin>
More information about the llvm-commits
mailing list