Optional<Symbol *> ObjFile::createDefined(
COFFSymbolRef Sym,
std::vector<const coff_aux_section_definition *> &ComdatDefs) {
- StringRef Name;
+ auto GetName = [&]() {
+ StringRef S;
+ COFFObj->getSymbolName(Sym, S);
+ return S;
+ };
+
if (Sym.isCommon()) {
auto *C = make<CommonChunk>(Sym);
Chunks.push_back(C);
- COFFObj->getSymbolName(Sym, Name);
- Symbol *S =
- Symtab->addCommon(this, Name, Sym.getValue(), Sym.getGeneric(), C);
- return S;
+ return Symtab->addCommon(this, GetName(), Sym.getValue(), Sym.getGeneric(),
+ C);
}
+
if (Sym.isAbsolute()) {
- COFFObj->getSymbolName(Sym, Name);
+ StringRef Name = GetName();
+
// Skip special symbols.
if (Name == "@comp.id")
return nullptr;
Feat00Flags = Sym.getValue();
return nullptr;
}
+
if (Sym.isExternal())
return Symtab->addAbsolute(Name, Sym);
- else
- return make<DefinedAbsolute>(Name, Sym);
+ return make<DefinedAbsolute>(Name, Sym);
}
+
int32_t SectionNumber = Sym.getSectionNumber();
if (SectionNumber == llvm::COFF::IMAGE_SYM_DEBUG)
return nullptr;
if (llvm::COFF::isReservedSectionNumber(SectionNumber))
- fatal(toString(this) + ": " + Name +
+ fatal(toString(this) + ": " + GetName() +
" should not refer to special section " + Twine(SectionNumber));
if ((uint32_t)SectionNumber >= SparseChunks.size())
- fatal(toString(this) + ": " + Name +
+ fatal(toString(this) + ": " + GetName() +
" should not refer to non-existent section " + Twine(SectionNumber));
// Handle comdat leader symbols.
Symbol *Leader;
bool Prevailing;
if (Sym.isExternal()) {
- COFFObj->getSymbolName(Sym, Name);
std::tie(Leader, Prevailing) =
- Symtab->addComdat(this, Name, Sym.getGeneric());
+ Symtab->addComdat(this, GetName(), Sym.getGeneric());
} else {
Leader = make<DefinedRegular>(this, /*Name*/ "", false,
/*IsExternal*/ false, Sym.getGeneric());
Prevailing = true;
}
+
if (Prevailing) {
- SectionChunk *C = readSection(SectionNumber, Def, Name);
+ SectionChunk *C = readSection(SectionNumber, Def, GetName());
SparseChunks[SectionNumber] = C;
C->Sym = cast<DefinedRegular>(Leader);
cast<DefinedRegular>(Leader)->Data = &C->Repl;
--- /dev/null
+# RUN: yaml2obj %s > %t.obj
+# RUN: not lld-link %t.obj 2>&1 | FileCheck %s
+
+# CHECK: foo should not refer to special section -10
+
+--- !COFF
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: foo
+ Value: 0
+ SectionNumber: -10
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...