[ELF][MIPS] Check that a section has a valid reference to a file in the isMipsPIC routine

llvm-svn: 331470
This commit is contained in:
Simon Atanasyan 2018-05-03 17:33:10 +00:00
parent 96fde08f3b
commit bc4da23133
2 changed files with 29 additions and 9 deletions

View File

@ -663,7 +663,11 @@ template <class ELFT> bool elf::isMipsPIC(const Defined *Sym) {
return false;
auto *Sec = cast<InputSectionBase>(Sym->Section);
const Elf_Ehdr *Hdr = Sec->template getFile<ELFT>()->getObj().getHeader();
ObjFile<ELFT> *File = Sec->template getFile<ELFT>();
if (!File)
return false;
const Elf_Ehdr *Hdr = File->getObj().getHeader();
return (Sym->StOther & STO_MIPS_MIPS16) == STO_MIPS_PIC ||
(Hdr->e_flags & EF_MIPS_PIC);
}

View File

@ -7,13 +7,14 @@
# RUN: -mattr=micromips %s -o %t-exe.o
# RUN: ld.lld %t-exe.o %t.so -o %t.exe
# RUN: llvm-readobj -t -dt -mips-plt-got %t.exe | FileCheck %s
# RUN: llvm-objdump -d -mattr=micromips %t.exe | FileCheck --check-prefix=ASM %s
# REQUIRES: mips
# CHECK: Symbols [
# CHECK: Symbol {
# CHECK: Name: foo
# CHECK-NEXT: Value: 0x20008
# CHECK-NEXT: Value: 0x20010
# CHECK-NEXT: Size:
# CHECK-NEXT: Binding: Local
# CHECK-NEXT: Type: None
@ -36,22 +37,26 @@
# CHECK-NEXT: }
# CHECK: Symbol {
# CHECK: Name: foo0
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: Value: 0x20040
# CHECK-NEXT: Size:
# CHECK-NEXT: Binding: Global
# CHECK-NEXT: Type: Function
# CHECK-NEXT: Other: 0
# CHECK-NEXT: Other [
# CHECK-NEXT: STO_MIPS_PLT
# CHECK-NEXT: ]
# CHECK-NEXT: Section: Undefined
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK: DynamicSymbols [
# CHECK: Symbol {
# CHECK: Name: foo0
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: Value: 0x20040
# CHECK-NEXT: Size:
# CHECK-NEXT: Binding: Global
# CHECK-NEXT: Type: Function
# CHECK-NEXT: Other: 0
# CHECK-NEXT: Other [
# CHECK-NEXT: STO_MIPS_PLT
# CHECK-NEXT: ]
# CHECK-NEXT: Section: Undefined
# CHECK-NEXT: }
# CHECK-NEXT: ]
@ -61,7 +66,7 @@
# CHECK-NEXT: Entry {
# CHECK-NEXT: Address:
# CHECK-NEXT: Access:
# CHECK-NEXT: Initial: 0x20009
# CHECK-NEXT: Initial: 0x20011
# CHECK-NEXT: }
# CHECK: ]
# CHECK: }
@ -70,8 +75,8 @@
# CHECK: Entries [
# CHECK-NEXT: Entry {
# CHECK-NEXT: Address:
# CHECK-NEXT: Initial: 0x20011
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: Initial: 0x20021
# CHECK-NEXT: Value: 0x20040
# CHECK-NEXT: Type: Function
# CHECK-NEXT: Section: Undefined
# CHECK-NEXT: Name: foo0@
@ -79,6 +84,15 @@
# CHECK-NEXT: ]
# CHECK-NEXT: }
# ASM: __start:
# ASM-NEXT: 20000: fd 1c 80 18 lw $8, -32744($gp)
# ASM-NEXT: 20004: 11 08 00 10 addi $8, $8, 16
# ASM-NEXT: 20008: 41 a8 00 02 lui $8, 2
# ASM-NEXT: 2000c: 11 08 00 40 addi $8, $8, 64
#
# ASM: foo:
# ASM-NEXT: 20010: f4 01 00 20 jal 131136
.text
.set micromips
.global foo
@ -87,5 +101,7 @@
__start:
lw $t0,%got(foo)($gp)
addi $t0,$t0,%lo(foo)
lui $t0,%hi(foo0)
addi $t0,$t0,%lo(foo0)
foo:
jal foo0