[lld] r198790 - [Mips] GOT16 relocation against non-local symbol does not require a
Simon Atanasyan
simon at atanasyan.com
Wed Jan 8 12:43:03 PST 2014
Author: atanasyan
Date: Wed Jan 8 14:43:03 2014
New Revision: 198790
URL: http://llvm.org/viewvc/llvm-project?rev=198790&view=rev
Log:
[Mips] GOT16 relocation against non-local symbol does not require a
paired LO16 relocation.
Added:
lld/trunk/test/elf/Mips/Inputs/got16.o
lld/trunk/test/elf/Mips/Inputs/got16.s
lld/trunk/test/elf/Mips/got16.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h?rev=198790&r1=198789&r2=198790&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h Wed Jan 8 14:43:03 2014
@@ -17,7 +17,9 @@ namespace elf {
/// \brief Mips internal references.
enum {
/// \brief Do nothing but mark GOT entry as a global one.
- LLD_R_MIPS_GLOBAL_GOT = 1024
+ LLD_R_MIPS_GLOBAL_GOT = 1024,
+ /// \brief The same as R_MIPS_GOT16 but for global symbols.
+ LLD_R_MIPS_GLOBAL_GOT16 = 1025
};
typedef llvm::object::ELFType<llvm::support::little, 2, false> Mips32ElELFType;
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp?rev=198790&r1=198789&r2=198790&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Wed Jan 8 14:43:03 2014
@@ -184,6 +184,10 @@ error_code MipsTargetRelocationHandler::
case LLD_R_MIPS_GLOBAL_GOT:
// Do nothing.
break;
+ case LLD_R_MIPS_GLOBAL_GOT16:
+ relocGOT16(location, relocVAddress, targetVAddress, ref.addend(),
+ _targetHandler.getGPDispSymAddr());
+ break;
default: {
std::string str;
llvm::raw_string_ostream s(str);
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp?rev=198790&r1=198789&r2=198790&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp Wed Jan 8 14:43:03 2014
@@ -118,7 +118,15 @@ private:
}
}
+ bool isLocal(const Atom *a) {
+ return isa<DefinedAtom>(a) &&
+ dyn_cast<DefinedAtom>(a)->scope() == Atom::scopeTranslationUnit;
+ }
+
void handleGOT(const Reference &ref) {
+ if (ref.kindValue() == R_MIPS_GOT16 && !isLocal(ref.target()))
+ const_cast<Reference &>(ref).setKindValue(LLD_R_MIPS_GLOBAL_GOT16);
+
const_cast<Reference &>(ref).setTarget(getGOTEntry(ref.target()));
}
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp?rev=198790&r1=198789&r2=198790&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsTargetHandler.cpp Wed Jan 8 14:43:03 2014
@@ -188,5 +188,6 @@ const Registry::KindStrings MipsTargetHa
LLD_KIND_STRING_ENTRY(R_MIPS_CALL16),
LLD_KIND_STRING_ENTRY(R_MIPS_JALR),
LLD_KIND_STRING_ENTRY(LLD_R_MIPS_GLOBAL_GOT),
+ LLD_KIND_STRING_ENTRY(LLD_R_MIPS_GLOBAL_GOT16),
LLD_KIND_STRING_END
};
Added: lld/trunk/test/elf/Mips/Inputs/got16.o
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/Inputs/got16.o?rev=198790&view=auto
==============================================================================
Binary files lld/trunk/test/elf/Mips/Inputs/got16.o (added) and lld/trunk/test/elf/Mips/Inputs/got16.o Wed Jan 8 14:43:03 2014 differ
Added: lld/trunk/test/elf/Mips/Inputs/got16.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/Inputs/got16.s?rev=198790&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/Inputs/got16.s (added)
+++ lld/trunk/test/elf/Mips/Inputs/got16.s Wed Jan 8 14:43:03 2014
@@ -0,0 +1,23 @@
+# as -mips32r2 -EL -o got16.o got16.s
+ .global glob
+ .ent glob
+glob:
+ lw $4,%got(local)($28)
+ addiu $4,$4,%lo(local)
+ lw $4,%got(hidden)($28)
+ lw $4,%call16(glob)($28)
+ lw $4,%call16(extern)($28)
+ .end glob
+
+ .data
+ .type local,%object
+ .size local,4
+local:
+ .word undef
+
+ .globl hidden
+ .hidden hidden
+ .type hidden,%object
+ .size hidden,4
+hidden:
+ .word 0
Added: lld/trunk/test/elf/Mips/got16.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/got16.test?rev=198790&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/got16.test (added)
+++ lld/trunk/test/elf/Mips/got16.test Wed Jan 8 14:43:03 2014
@@ -0,0 +1,83 @@
+# Check handling of global/local GOT16 relocations.
+RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec \
+RUN: --output-filetype=yaml -o %t %p/Inputs/got16.o
+RUN: FileCheck %s < %t
+
+CHECK: - ref-name: L002
+CHECK: type: got
+CHECK: content: [ 00, 00, 00, 00 ]
+CHECK: alignment: 2^2
+CHECK: section-choice: custom-required
+CHECK: section-name: .got
+CHECK: permissions: rw-
+CHECK: references:
+CHECK: - kind: R_MIPS_32
+CHECK: offset: 0
+CHECK: target: L003
+CHECK: - ref-name: L004
+CHECK: type: got
+CHECK: content: [ 00, 00, 00, 00 ]
+CHECK: alignment: 2^2
+CHECK: section-choice: custom-required
+CHECK: section-name: .got
+CHECK: permissions: rw-
+CHECK: references:
+CHECK: - kind: R_MIPS_32
+CHECK: offset: 0
+CHECK: target: hidden
+CHECK: - ref-name: L005
+CHECK: type: got
+CHECK: content: [ 00, 00, 00, 00 ]
+CHECK: alignment: 2^2
+CHECK: section-choice: custom-required
+CHECK: section-name: .got
+CHECK: permissions: rw-
+CHECK: references:
+CHECK: - kind: LLD_R_MIPS_GLOBAL_GOT
+CHECK: offset: 0
+CHECK: target: glob
+CHECK: - kind: R_MIPS_32
+CHECK: offset: 0
+CHECK: target: glob
+CHECK: - ref-name: L006
+CHECK: type: got
+CHECK: content: [ 00, 00, 00, 00 ]
+CHECK: alignment: 2^2
+CHECK: section-choice: custom-required
+CHECK: section-name: .got
+CHECK: permissions: rw-
+CHECK: references:
+CHECK: - kind: LLD_R_MIPS_GLOBAL_GOT
+CHECK: offset: 0
+CHECK: target: extern
+CHECK: - ref-name: L007
+CHECK: alignment: 2^4
+CHECK: references:
+CHECK: - kind: layout-after
+CHECK: offset: 0
+CHECK: target: glob
+CHECK: - name: glob
+CHECK: scope: global
+CHECK: content: [ 00, 00, 84, 8F, 00, 00, 84, 24, 00, 00, 84, 8F,
+CHECK: 00, 00, 84, 8F, 00, 00, 84, 8F, 00, 00, 00, 00,
+CHECK: 00, 00, 00, 00, 00, 00, 00, 00 ]
+CHECK: alignment: 2^4
+CHECK: references:
+CHECK: - kind: R_MIPS_GOT16
+CHECK: offset: 0
+CHECK: target: L002
+CHECK: - kind: R_MIPS_LO16
+CHECK: offset: 4
+CHECK: target: L003
+CHECK: - kind: LLD_R_MIPS_GLOBAL_GOT16
+CHECK: offset: 8
+CHECK: target: L004
+CHECK: - kind: R_MIPS_CALL16
+CHECK: offset: 12
+CHECK: target: L005
+CHECK: - kind: R_MIPS_CALL16
+CHECK: offset: 16
+CHECK: target: L006
+CHECK: - kind: layout-before
+CHECK: offset: 0
+CHECK: target: L007
More information about the llvm-commits
mailing list