Avoid crash with local abs symbol.

llvm-svn: 310736
This commit is contained in:
Rafael Espindola 2017-08-11 17:47:12 +00:00
parent 6ac981151e
commit db1af69342
2 changed files with 14 additions and 6 deletions

View File

@ -131,8 +131,13 @@ SymbolBody::SymbolBody(Kind K, StringRefZ Name, bool IsLocal, uint8_t StOther,
Name(Name) {}
InputFile *SymbolBody::getFile() const {
if (isLocal())
return cast<InputSectionBase>(cast<DefinedRegular>(this)->Section)->File;
if (isLocal()) {
const SectionBase *Sec = cast<DefinedRegular>(this)->Section;
// Local absolute symbols actually have a file, but that is not currently
// used. We could support that by having a mostly redundant InputFile in
// SymbolBody, or having a special absolute section if needed.
return Sec ? cast<InputSectionBase>(Sec)->File : nullptr;
}
return symbol()->File;
}

View File

@ -25,6 +25,9 @@ bar:
.long zed - .
local:
.comm common,4,16
.global abs
abs = 0xAB5
labs = 0x1AB5
// CHECK: Address Size Align Out In Symbol
// CHECK-NEXT: 0000000000200158 0000000000000030 8 .eh_frame
@ -48,12 +51,12 @@ local:
// CHECK-NEXT: 0000000000202000 0000000000000004 0 common
// CHECK-NEXT: 0000000000000000 0000000000000008 1 .comment
// CHECK-NEXT: 0000000000000000 0000000000000008 1 <internal>:(.comment)
// CHECK-NEXT: 0000000000000000 00000000000000f0 8 .symtab
// CHECK-NEXT: 0000000000000000 00000000000000f0 8 <internal>:(.symtab)
// CHECK-NEXT: 0000000000000000 0000000000000120 8 .symtab
// CHECK-NEXT: 0000000000000000 0000000000000120 8 <internal>:(.symtab)
// CHECK-NEXT: 0000000000000000 0000000000000039 1 .shstrtab
// CHECK-NEXT: 0000000000000000 0000000000000039 1 <internal>:(.shstrtab)
// CHECK-NEXT: 0000000000000000 000000000000002f 1 .strtab
// CHECK-NEXT: 0000000000000000 000000000000002f 1 <internal>:(.strtab)
// CHECK-NEXT: 0000000000000000 0000000000000038 1 .strtab
// CHECK-NEXT: 0000000000000000 0000000000000038 1 <internal>:(.strtab)
// RUN: not ld.lld %t1.o %t2.o %t3.o %t4.a -o %t -Map=/ 2>&1 \
// RUN: | FileCheck -check-prefix=FAIL %s