diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2017-12-28 00:23:49 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2017-12-28 00:23:49 +0000 |
| commit | 465e7c94edd529a4645944d423a2181660850c6a (patch) | |
| tree | 9921b24552967d85bc56811a888824ebf786a97f | |
| parent | 520d055f66277541337c686944f47fb871bdd25b (diff) | |
| download | bcm5719-llvm-465e7c94edd529a4645944d423a2181660850c6a.tar.gz bcm5719-llvm-465e7c94edd529a4645944d423a2181660850c6a.zip | |
Allow copy relocation with -z notext.
This makes adjustExpr a bit simpler too IMHO.
It seems that some of the complication around relocation processing
is that we are trying to create copy relocations too early. It seems
we could handle a few simple cases first and continue.
llvm-svn: 321507
| -rw-r--r-- | lld/ELF/Relocations.cpp | 13 | ||||
| -rw-r--r-- | lld/test/ELF/Inputs/znotext-copy-relocations.s | 5 | ||||
| -rw-r--r-- | lld/test/ELF/x86-64-dyn-rel-error.s | 2 | ||||
| -rw-r--r-- | lld/test/ELF/x86-64-dyn-rel-error2.s | 2 | ||||
| -rw-r--r-- | lld/test/ELF/znotext-copy-relocation.s | 16 |
5 files changed, 31 insertions, 7 deletions
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 4654158bc0b..1aa0957b1d0 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -581,6 +581,8 @@ static RelExpr getPltExpr(Symbol &Sym, RelExpr Expr, bool &IsConstant) { return toPlt(Expr); } +// This modifies the expression if we can use a copy relocation or point the +// symbol to the PLT. template <class ELFT> static RelExpr adjustExpr(Symbol &Sym, RelExpr Expr, RelType Type, InputSectionBase &S, uint64_t RelOff, @@ -608,13 +610,9 @@ static RelExpr adjustExpr(Symbol &Sym, RelExpr Expr, RelType Type, // linker to write a value to read only memory or use an unsupported // relocation. - // FIXME: This is a hack to avoid changing error messages for now. - if (CanWrite && !Sym.isFunc()) - return Expr; - // We can hack around it if we are producing an executable and // the refered symbol can be preemepted to refer to the executable. - if (Config->Shared || (Config->Pic && !isRelExpr(Expr))) { + if (!CanWrite && (Config->Shared || (Config->Pic && !isRelExpr(Expr)))) { error( "can't create dynamic relocation " + toString(Type) + " against " + (Sym.getName().empty() ? "local symbol" : "symbol: " + toString(Sym)) + @@ -623,6 +621,11 @@ static RelExpr adjustExpr(Symbol &Sym, RelExpr Expr, RelType Type, return Expr; } + // Copy relocations are only possible if we are creating an executable and the + // symbol is shared. + if (!Sym.isShared() || Config->Shared) + return Expr; + if (Sym.getVisibility() != STV_DEFAULT) { error("cannot preempt symbol: " + toString(Sym) + getLocation(S, Sym, RelOff)); diff --git a/lld/test/ELF/Inputs/znotext-copy-relocations.s b/lld/test/ELF/Inputs/znotext-copy-relocations.s new file mode 100644 index 00000000000..a23abbe3d40 --- /dev/null +++ b/lld/test/ELF/Inputs/znotext-copy-relocations.s @@ -0,0 +1,5 @@ +.global foo +.type foo,@object +.size foo, 8 +foo: +.quad 42 diff --git a/lld/test/ELF/x86-64-dyn-rel-error.s b/lld/test/ELF/x86-64-dyn-rel-error.s index 3413901db9a..7a705eb5417 100644 --- a/lld/test/ELF/x86-64-dyn-rel-error.s +++ b/lld/test/ELF/x86-64-dyn-rel-error.s @@ -2,7 +2,7 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/shared.s -o %t2.o // RUN: ld.lld %t2.o -shared -o %t2.so -// RUN: not ld.lld %t.o %t2.so -o %t 2>&1 | FileCheck %s +// RUN: not ld.lld -shared %t.o %t2.so -o %t 2>&1 | FileCheck %s .global _start _start: diff --git a/lld/test/ELF/x86-64-dyn-rel-error2.s b/lld/test/ELF/x86-64-dyn-rel-error2.s index 209efb31289..9b731e26887 100644 --- a/lld/test/ELF/x86-64-dyn-rel-error2.s +++ b/lld/test/ELF/x86-64-dyn-rel-error2.s @@ -2,7 +2,7 @@ // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/shared.s -o %t2.o // RUN: ld.lld %t2.o -shared -o %t2.so -// RUN: not ld.lld %t.o %t2.so -o %t 2>&1 | FileCheck %s +// RUN: not ld.lld -shared %t.o %t2.so -o %t 2>&1 | FileCheck %s // CHECK: relocation R_X86_64_PC32 cannot be used against shared object; recompile with -fPIC // CHECK: >>> defined in {{.*}}.so diff --git a/lld/test/ELF/znotext-copy-relocation.s b/lld/test/ELF/znotext-copy-relocation.s new file mode 100644 index 00000000000..a5fc4f99dba --- /dev/null +++ b/lld/test/ELF/znotext-copy-relocation.s @@ -0,0 +1,16 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/znotext-copy-relocations.s -o %t2.o +# RUN: ld.lld %t2.o -o %t2.so -shared +# RUN: ld.lld -z notext %t.o %t2.so -o %t +# RUN: llvm-readobj -r %t | FileCheck %s + +# CHECK: Relocations [ +# CHECK-NEXT: Section ({{.*}}) .rela.dyn { +# CHECK-NEXT: R_X86_64_COPY foo 0x0 +# CHECK-NEXT: } +# CHECK-NEXT: ] + +.global _start +_start: +.long foo |

