[lld] r282716 - [ELF][MIPS] Set GP0 value to zero in case of relocatable object generation
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 29 05:58:48 PDT 2016
Author: atanasyan
Date: Thu Sep 29 07:58:48 2016
New Revision: 282716
URL: http://llvm.org/viewvc/llvm-project?rev=282716&view=rev
Log:
[ELF][MIPS] Set GP0 value to zero in case of relocatable object generation
LLD does not update relocations addends when generate a relocatable
object. That is why we should not write a non-zero GP0 value into
the .reginfo and .MIPS.options sections. And we should not accept input
object files with non-zero GP0 value because we cannot handle them
properly.
Added:
lld/trunk/test/ELF/Inputs/mips-gp0-non-zero.o (with props)
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/OutputSections.cpp
lld/trunk/test/ELF/mips-gprel32-relocs-gp0.s
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=282716&r1=282715&r2=282716&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Sep 29 07:58:48 2016
@@ -659,6 +659,8 @@ MipsReginfoInputSection<ELFT>::MipsRegin
return;
}
Reginfo = reinterpret_cast<const Elf_Mips_RegInfo<ELFT> *>(Data.data());
+ if (Reginfo->ri_gp_value)
+ error(getName(this) + ": unsupported non-zero ri_gp_value");
}
template <class ELFT>
@@ -682,6 +684,8 @@ MipsOptionsInputSection<ELFT>::MipsOptio
auto *O = reinterpret_cast<const Elf_Mips_Options<ELFT> *>(D.data());
if (O->kind == ODK_REGINFO) {
Reginfo = &O->getRegInfo();
+ if (Reginfo->ri_gp_value)
+ error(getName(this) + ": unsupported non-zero ri_gp_value");
break;
}
D = D.slice(O->size);
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=282716&r1=282715&r2=282716&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Thu Sep 29 07:58:48 2016
@@ -1740,7 +1740,10 @@ MipsReginfoOutputSection<ELFT>::MipsRegi
template <class ELFT>
void MipsReginfoOutputSection<ELFT>::writeTo(uint8_t *Buf) {
auto *R = reinterpret_cast<Elf_Mips_RegInfo *>(Buf);
- R->ri_gp_value = Out<ELFT>::Got->getVA() + MipsGPOffset;
+ if (Config->Relocatable)
+ R->ri_gp_value = 0;
+ else
+ R->ri_gp_value = Out<ELFT>::Got->getVA() + MipsGPOffset;
R->ri_gprmask = GprMask;
}
@@ -1769,7 +1772,10 @@ void MipsOptionsOutputSection<ELFT>::wri
Opt->section = 0;
Opt->info = 0;
auto *Reg = reinterpret_cast<Elf_Mips_RegInfo *>(Buf + sizeof(*Opt));
- Reg->ri_gp_value = Out<ELFT>::Got->getVA() + MipsGPOffset;
+ if (Config->Relocatable)
+ Reg->ri_gp_value = 0;
+ else
+ Reg->ri_gp_value = Out<ELFT>::Got->getVA() + MipsGPOffset;
Reg->ri_gprmask = GprMask;
}
Added: lld/trunk/test/ELF/Inputs/mips-gp0-non-zero.o
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/mips-gp0-non-zero.o?rev=282716&view=auto
==============================================================================
Binary files lld/trunk/test/ELF/Inputs/mips-gp0-non-zero.o (added) and lld/trunk/test/ELF/Inputs/mips-gp0-non-zero.o Thu Sep 29 07:58:48 2016 differ
Propchange: lld/trunk/test/ELF/Inputs/mips-gp0-non-zero.o
------------------------------------------------------------------------------
svn:executable = *
Modified: lld/trunk/test/ELF/mips-gprel32-relocs-gp0.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-gprel32-relocs-gp0.s?rev=282716&r1=282715&r2=282716&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-gprel32-relocs-gp0.s (original)
+++ lld/trunk/test/ELF/mips-gprel32-relocs-gp0.s Thu Sep 29 07:58:48 2016
@@ -1,29 +1,35 @@
-# Check R_MIPS_GPREL32 relocation calculation if input file conatins
-# non-zero GP0 value in the .reginfo section.
+# Check that relocatable object produced by LLD has zero gp0 value.
+# Also check an error message if input object file has non-zero gp0 value.
+# mips-gp0-non-zero.o is a relocatable object produced from the asm code
+# below and linked by GNU bfd linker.
# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
# RUN: ld.lld -r -o %t-r.o %t.o
# RUN: ld.lld -shared -o %t.so %t-r.o
# RUN: llvm-readobj -mips-reginfo %t-r.o %t.so | FileCheck %s
# RUN: llvm-objdump -s -t %t.so | FileCheck --check-prefix=DUMP %s
+# RUN: not ld.lld -shared -o %t.so %S/Inputs/mips-gp0-non-zero.o 2>&1 \
+# RUN: | FileCheck --check-prefix=ERR %s
# REQUIRES: mips
# CHECK: {{.*}}mips-gprel32-relocs-gp0.s.tmp-r.o
-# CHECK: GP: 0x7FF0
+# CHECK: GP: 0x0
# CHECK: {{.*}}mips-gprel32-relocs-gp0.s.tmp.so
# CHECK: GP: 0x27FF0
# DUMP: Contents of section .rodata:
-# DUMP: 0114 ffff0004 ffff0008
-# ^ 0x10004 + 0x7ff0 - 0x27ff0
-# ^ 0x10008 + 0x7ff0 - 0x27ff0
+# DUMP: 0114 fffe8014 fffe8018
+# ^ 0x10004 + 0 - 0x27ff0
+# ^ 0x10008 + 0 - 0x27ff0
# DUMP: SYMBOL TABLE:
# DUMP: 00010008 .text 00000000 bar
# DUMP: 00010004 .text 00000000 foo
# DUMP: 00027ff0 .got 00000000 .hidden _gp
+# ERR: {{.*}}mips-gp0-non-zero.o(.reginfo): unsupported non-zero ri_gp_value
+
.text
.global __start
__start:
More information about the llvm-commits
mailing list