diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2018-01-03 01:24:58 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2018-01-03 01:24:58 +0000 |
commit | 4b2350d79be74e86b24da35d31f1f9ccc9663037 (patch) | |
tree | 470aa88ff3f9cd9b8cc715e4e95a1dc8efaccf6d | |
parent | 50e291eaf28383e8b9c061dedc3aa0acb9d0c9e6 (diff) | |
download | bcm5719-llvm-4b2350d79be74e86b24da35d31f1f9ccc9663037.tar.gz bcm5719-llvm-4b2350d79be74e86b24da35d31f1f9ccc9663037.zip |
Produce relocations with weak undef if the section is RW.
If a section is RW there is no reason to drop a relocation with a weak
undefined symbol.
llvm-svn: 321684
-rw-r--r-- | lld/ELF/Relocations.cpp | 12 | ||||
-rw-r--r-- | lld/test/ELF/weak-undef-rw.s | 12 |
2 files changed, 18 insertions, 6 deletions
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 1aa0957b1d0..1ab313dbe32 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -592,6 +592,12 @@ static RelExpr adjustExpr(Symbol &Sym, RelExpr Expr, RelType Type, if (IsConstant) return Expr; + // We can create any dynamic relocation supported by the dynamic linker if a + // section is writable or we are passed -z notext. + bool CanWrite = (S.Flags & SHF_WRITE) || !Config->ZText; + if (CanWrite && Target->isPicRel(Type)) + return Expr; + // If the relocation is to a weak undef, and we are producing // executable, give up on it and produce a non preemptible 0. if (!Config->Shared && Sym.isUndefWeak()) { @@ -600,12 +606,6 @@ static RelExpr adjustExpr(Symbol &Sym, RelExpr Expr, RelType Type, return Expr; } - // We can create any dynamic relocation supported by the dynamic linker if a - // section is writable or we are passed -z notext. - bool CanWrite = (S.Flags & SHF_WRITE) || !Config->ZText; - if (CanWrite && Target->isPicRel(Type)) - return Expr; - // If we got here we know that this relocation would require the dynamic // linker to write a value to read only memory or use an unsupported // relocation. diff --git a/lld/test/ELF/weak-undef-rw.s b/lld/test/ELF/weak-undef-rw.s new file mode 100644 index 00000000000..c75e7d67db3 --- /dev/null +++ b/lld/test/ELF/weak-undef-rw.s @@ -0,0 +1,12 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld %t.o -o %t --export-dynamic +# RUN: llvm-readobj -r %t | FileCheck %s + +# CHECK: R_X86_64_64 foobar 0x0 + + .global _start +_start: + .data + .weak foobar + .quad foobar |