diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2019-08-09 00:57:54 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2019-08-09 00:57:54 +0000 |
commit | 1fa1cd200b9a005629ca4793a99dd970c7a14371 (patch) | |
tree | 151396a6abe9fe65dd66a044835fb82ec935488b /lld | |
parent | 52a36fae2a3f8560a5be690a67304db5edafc3fe (diff) | |
download | llvm-1fa1cd200b9a005629ca4793a99dd970c7a14371.zip llvm-1fa1cd200b9a005629ca4793a99dd970c7a14371.tar.gz llvm-1fa1cd200b9a005629ca4793a99dd970c7a14371.tar.bz2 |
ELF: Move sections referred to by __start_/__stop_ symbols into the main partition.
In the case where C identifier sections have SHF_LINK_ORDER they will most
likely be placed in the same partition as the section that they are associated
with. But unless this happens to be the main partition, this will cause them
to be excluded from the range covered by the __start_ and __stop_ symbols,
which may lead to incorrect program behaviour. So we need to move them
all into the main partition so that they will be covered by the __start_
and __stop_ symbols.
We may want to refine this approach later and allow different __start_/__stop_
symbol values for different partitions. This would only make sense for
relocations from SHT_NOTE sections since they are duplicated into each
partition.
Differential Revision: https://reviews.llvm.org/D65909
llvm-svn: 368375
Diffstat (limited to 'lld')
-rw-r--r-- | lld/ELF/MarkLive.cpp | 12 | ||||
-rw-r--r-- | lld/test/ELF/partition-move-to-main-startstop.s | 43 |
2 files changed, 55 insertions, 0 deletions
diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index 36b847f..bd29be7 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -291,6 +291,10 @@ template <class ELFT> void MarkLive<ELFT>::mark() { // GOT, which means that the ifunc must be available when the main partition is // loaded) and TLS symbols (because we only know how to correctly process TLS // relocations for the main partition). +// +// We also need to move sections whose names are C identifiers that are referred +// to from __start_/__stop_ symbols because there will only be one set of +// symbols for the whole program. template <class ELFT> void MarkLive<ELFT>::moveToMain() { for (InputFile *file : objectFiles) for (Symbol *s : file->getSymbols()) @@ -299,6 +303,14 @@ template <class ELFT> void MarkLive<ELFT>::moveToMain() { d->section->isLive()) markSymbol(s); + for (InputSectionBase *sec : inputSections) { + if (!sec->isLive() || !isValidCIdentifier(sec->name)) + continue; + if (symtab->find(("__start_" + sec->name).str()) || + symtab->find(("__stop_" + sec->name).str())) + enqueue(sec, 0); + } + mark(); } diff --git a/lld/test/ELF/partition-move-to-main-startstop.s b/lld/test/ELF/partition-move-to-main-startstop.s new file mode 100644 index 0000000..76c0495 --- /dev/null +++ b/lld/test/ELF/partition-move-to-main-startstop.s @@ -0,0 +1,43 @@ +// REQUIRES: x86 +// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=x86_64-unknown-linux +// RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections +// RUN: llvm-readelf -S %t | FileCheck --implicit-check-not=has_startstop %s + +// We can't let the has_startstop section be split by partition because it is +// referenced by __start_ and __stop_ symbols, so the split could result in +// some sections being moved out of the __start_/__stop_ range. Make sure that +// that didn't happen by checking that there is only one section. +// +// It's fine for us to split no_startstop because of the lack of +// __start_/__stop_ symbols. + +// CHECK: has_startstop +// CHECK: no_startstop + +// CHECK: no_startstop + +.section .llvm_sympart.f1,"",@llvm_sympart +.asciz "part1" +.quad f1 + +.section .text._start,"ax",@progbits +.globl _start +_start: +call __start_has_startstop +call __stop_has_startstop + +.section .text.f1,"ax",@progbits +.globl f1 +f1: + +.section has_startstop,"ao",@progbits,.text._start,unique,1 +.quad 1 + +.section has_startstop,"ao",@progbits,.text.f1,unique,2 +.quad 2 + +.section no_startstop,"ao",@progbits,.text._start,unique,1 +.quad 3 + +.section no_startstop,"ao",@progbits,.text.f1,unique,2 +.quad 4 |