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>
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);
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;
}
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;
}
-# 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: