[llvm] r371380 - [lib/ObjectYAML] - Improve and cleanup error reporting in ELFState<ELFT> class.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 9 02:43:03 PDT 2019
Author: grimar
Date: Mon Sep 9 02:43:03 2019
New Revision: 371380
URL: http://llvm.org/viewvc/llvm-project?rev=371380&view=rev
Log:
[lib/ObjectYAML] - Improve and cleanup error reporting in ELFState<ELFT> class.
The aim of this patch is to refactor how we handle and report error.
I suggest to use the same approach we use in LLD: delayed error reporting.
For that I introduced 'HasError' flag which triggers when we report an error.
Now we do not exit instantly on any error. The benefits are:
1) There are no more 'exit(1)' calls in the library code.
2) Code was simplified significantly in a few places.
3) It is now possible to print multiple errors instead of only one.
Also, I changed the messages to be lower case and removed a full stop.
Differential revision: https://reviews.llvm.org/D67182
Added:
llvm/trunk/test/tools/yaml2obj/elf-comdat-broken-members.yaml
Modified:
llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
llvm/trunk/test/tools/yaml2obj/duplicate-section-names.test
llvm/trunk/test/tools/yaml2obj/duplicate-symbol-names.test
llvm/trunk/test/tools/yaml2obj/dynamic-section-raw-content.yaml
llvm/trunk/test/tools/yaml2obj/dynamic-symbols.yaml
llvm/trunk/test/tools/yaml2obj/dynsymtab-implicit-sections-size-content.yaml
llvm/trunk/test/tools/yaml2obj/elf-comdat-broken-info.yaml
llvm/trunk/test/tools/yaml2obj/elf-custom-null-section.yaml
llvm/trunk/test/tools/yaml2obj/program-header.yaml
llvm/trunk/test/tools/yaml2obj/reloc-sec-info.yaml
llvm/trunk/test/tools/yaml2obj/relocation-missing-symbol.yaml
llvm/trunk/test/tools/yaml2obj/section-link.yaml
llvm/trunk/test/tools/yaml2obj/symtab-implicit-sections-size-content.yaml
Modified: llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp?rev=371380&r1=371379&r2=371380&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp Mon Sep 9 02:43:03 2019
@@ -114,12 +114,20 @@ template <class ELFT> class ELFState {
NameToIdxMap DynSymN2I;
ELFYAML::Object &Doc;
- bool buildSectionIndex();
- bool buildSymbolIndexes();
+ bool HasError = false;
+
+ std::vector<Elf_Sym> toELFSymbols(ArrayRef<ELFYAML::Symbol> Symbols,
+ const StringTableBuilder &Strtab);
+ unsigned toSectionIndex(StringRef S, StringRef LocSec, StringRef LocSym = "");
+ unsigned toSymbolIndex(StringRef S, StringRef LocSec, bool IsDynamic);
+ void reportError(const Twine &Msg);
+
+ void buildSectionIndex();
+ void buildSymbolIndexes();
void initProgramHeaders(std::vector<Elf_Phdr> &PHeaders);
bool initImplicitHeader(ContiguousBlobAccumulator &CBA, Elf_Shdr &Header,
StringRef SecName, ELFYAML::Section *YAMLSec);
- bool initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
+ void initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
ContiguousBlobAccumulator &CBA);
void initSymtabSectionHeader(Elf_Shdr &SHeader, SymtabType STType,
ContiguousBlobAccumulator &CBA,
@@ -132,34 +140,33 @@ template <class ELFT> class ELFState {
std::vector<Elf_Shdr> &SHeaders);
void finalizeStrings();
void writeELFHeader(ContiguousBlobAccumulator &CBA, raw_ostream &OS);
- bool writeSectionContent(Elf_Shdr &SHeader,
+ void writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::RawContentSection &Section,
ContiguousBlobAccumulator &CBA);
- bool writeSectionContent(Elf_Shdr &SHeader,
+ void writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::RelocationSection &Section,
ContiguousBlobAccumulator &CBA);
- bool writeSectionContent(Elf_Shdr &SHeader, const ELFYAML::Group &Group,
+ void writeSectionContent(Elf_Shdr &SHeader, const ELFYAML::Group &Group,
ContiguousBlobAccumulator &CBA);
- bool writeSectionContent(Elf_Shdr &SHeader,
+ void writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::SymtabShndxSection &Shndx,
ContiguousBlobAccumulator &CBA);
- bool writeSectionContent(Elf_Shdr &SHeader,
+ void writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::SymverSection &Section,
ContiguousBlobAccumulator &CBA);
- bool writeSectionContent(Elf_Shdr &SHeader,
+ void writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::VerneedSection &Section,
ContiguousBlobAccumulator &CBA);
- bool writeSectionContent(Elf_Shdr &SHeader,
+ void writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::VerdefSection &Section,
ContiguousBlobAccumulator &CBA);
- bool writeSectionContent(Elf_Shdr &SHeader,
+ void writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::MipsABIFlags &Section,
ContiguousBlobAccumulator &CBA);
- bool writeSectionContent(Elf_Shdr &SHeader,
+ void writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::DynamicSection &Section,
ContiguousBlobAccumulator &CBA);
ELFState(ELFYAML::Object &D);
-
public:
static int writeELF(raw_ostream &OS, ELFYAML::Object &Doc);
};
@@ -258,14 +265,36 @@ void ELFState<ELFT>::initProgramHeaders(
}
}
-static bool convertSectionIndex(NameToIdxMap &SN2I, StringRef SecName,
- StringRef IndexSrc, unsigned &IndexDest) {
- if (!SN2I.lookup(IndexSrc, IndexDest) && !to_integer(IndexSrc, IndexDest)) {
- WithColor::error() << "Unknown section referenced: '" << IndexSrc
- << "' at YAML section '" << SecName << "'.\n";
- return false;
+template <class ELFT>
+unsigned ELFState<ELFT>::toSectionIndex(StringRef S, StringRef LocSec,
+ StringRef LocSym) {
+ unsigned Index;
+ if (SN2I.lookup(S, Index) || to_integer(S, Index))
+ return Index;
+
+ assert(LocSec.empty() || LocSym.empty());
+ if (!LocSym.empty())
+ reportError("unknown section referenced: '" + S + "' by YAML symbol '" +
+ LocSym + "'");
+ else
+ reportError("unknown section referenced: '" + S + "' by YAML section '" +
+ LocSec + "'");
+ return 0;
+}
+
+template <class ELFT>
+unsigned ELFState<ELFT>::toSymbolIndex(StringRef S, StringRef LocSec,
+ bool IsDynamic) {
+ const NameToIdxMap &SymMap = IsDynamic ? DynSymN2I : SymN2I;
+ unsigned Index;
+ // Here we try to look up S in the symbol table. If it is not there,
+ // treat its value as a symbol index.
+ if (!SymMap.lookup(S, Index) && !to_integer(S, Index)) {
+ reportError("unknown symbol referenced: '" + S + "' by YAML section '" +
+ LocSec + "'");
+ return 0;
}
- return true;
+ return Index;
}
template <class ELFT>
@@ -310,7 +339,7 @@ static StringRef dropUniqueSuffix(String
}
template <class ELFT>
-bool ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
+void ELFState<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
ContiguousBlobAccumulator &CBA) {
// Ensure SHN_UNDEF entry is present. An all-zero section header is a
// valid SHN_UNDEF entry since SHT_NULL == 0.
@@ -340,12 +369,8 @@ bool ELFState<ELFT>::initSectionHeaders(
SHeader.sh_addr = Sec->Address;
SHeader.sh_addralign = Sec->AddressAlign;
- if (!Sec->Link.empty()) {
- unsigned Index;
- if (!convertSectionIndex(SN2I, Sec->Name, Sec->Link, Index))
- return false;
- SHeader.sh_link = Index;
- }
+ if (!Sec->Link.empty())
+ SHeader.sh_link = toSectionIndex(Sec->Link, Sec->Name);
if (I == 0) {
if (auto RawSec = dyn_cast<ELFYAML::RawContentSection>(Sec)) {
@@ -358,20 +383,15 @@ bool ELFState<ELFT>::initSectionHeaders(
if (Sec->EntSize)
SHeader.sh_entsize = *Sec->EntSize;
} else if (auto S = dyn_cast<ELFYAML::RawContentSection>(Sec)) {
- if (!writeSectionContent(SHeader, *S, CBA))
- return false;
+ writeSectionContent(SHeader, *S, CBA);
} else if (auto S = dyn_cast<ELFYAML::SymtabShndxSection>(Sec)) {
- if (!writeSectionContent(SHeader, *S, CBA))
- return false;
+ writeSectionContent(SHeader, *S, CBA);
} else if (auto S = dyn_cast<ELFYAML::RelocationSection>(Sec)) {
- if (!writeSectionContent(SHeader, *S, CBA))
- return false;
+ writeSectionContent(SHeader, *S, CBA);
} else if (auto S = dyn_cast<ELFYAML::Group>(Sec)) {
- if (!writeSectionContent(SHeader, *S, CBA))
- return false;
+ writeSectionContent(SHeader, *S, CBA);
} else if (auto S = dyn_cast<ELFYAML::MipsABIFlags>(Sec)) {
- if (!writeSectionContent(SHeader, *S, CBA))
- return false;
+ writeSectionContent(SHeader, *S, CBA);
} else if (auto S = dyn_cast<ELFYAML::NoBitsSection>(Sec)) {
SHeader.sh_entsize = 0;
SHeader.sh_size = S->Size;
@@ -379,19 +399,16 @@ bool ELFState<ELFT>::initSectionHeaders(
// so just to setup the section offset.
CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
} else if (auto S = dyn_cast<ELFYAML::DynamicSection>(Sec)) {
- if (!writeSectionContent(SHeader, *S, CBA))
- return false;
+ writeSectionContent(SHeader, *S, CBA);
} else if (auto S = dyn_cast<ELFYAML::SymverSection>(Sec)) {
- if (!writeSectionContent(SHeader, *S, CBA))
- return false;
+ writeSectionContent(SHeader, *S, CBA);
} else if (auto S = dyn_cast<ELFYAML::VerneedSection>(Sec)) {
- if (!writeSectionContent(SHeader, *S, CBA))
- return false;
+ writeSectionContent(SHeader, *S, CBA);
} else if (auto S = dyn_cast<ELFYAML::VerdefSection>(Sec)) {
- if (!writeSectionContent(SHeader, *S, CBA))
- return false;
- } else
+ writeSectionContent(SHeader, *S, CBA);
+ } else {
llvm_unreachable("Unknown section type");
+ }
// Override the fields if requested.
if (Sec) {
@@ -403,8 +420,6 @@ bool ELFState<ELFT>::initSectionHeaders(
SHeader.sh_size = *Sec->ShSize;
}
}
-
- return true;
}
static size_t findFirstNonGlobal(ArrayRef<ELFYAML::Symbol> Symbols) {
@@ -430,11 +445,9 @@ static uint64_t writeRawSectionData(raw_
}
template <class ELFT>
-static std::vector<typename ELFT::Sym>
-toELFSymbols(NameToIdxMap &SN2I, ArrayRef<ELFYAML::Symbol> Symbols,
- const StringTableBuilder &Strtab) {
- using Elf_Sym = typename ELFT::Sym;
-
+std::vector<typename ELFT::Sym>
+ELFState<ELFT>::toELFSymbols(ArrayRef<ELFYAML::Symbol> Symbols,
+ const StringTableBuilder &Strtab) {
std::vector<Elf_Sym> Ret;
Ret.resize(Symbols.size() + 1);
@@ -451,18 +464,11 @@ toELFSymbols(NameToIdxMap &SN2I, ArrayRe
Symbol.st_name = Strtab.getOffset(dropUniqueSuffix(Sym.Name));
Symbol.setBindingAndType(Sym.Binding, Sym.Type);
- if (!Sym.Section.empty()) {
- unsigned Index;
- if (!SN2I.lookup(Sym.Section, Index)) {
- WithColor::error() << "Unknown section referenced: '" << Sym.Section
- << "' by YAML symbol " << Sym.Name << ".\n";
- exit(1);
- }
- Symbol.st_shndx = Index;
- } else if (Sym.Index) {
+ if (!Sym.Section.empty())
+ Symbol.st_shndx = toSectionIndex(Sym.Section, "", Sym.Name);
+ else if (Sym.Index)
Symbol.st_shndx = *Sym.Index;
- }
- // else Symbol.st_shndex == SHN_UNDEF (== 0), since it was zero'd earlier.
+
Symbol.st_value = Sym.Value;
Symbol.st_other = Sym.Other ? *Sym.Other : 0;
Symbol.st_size = Sym.Size;
@@ -484,18 +490,14 @@ void ELFState<ELFT>::initSymtabSectionHe
dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
if (RawSec && !Symbols.empty() && (RawSec->Content || RawSec->Size)) {
if (RawSec->Content)
- WithColor::error() << "Cannot specify both `Content` and " +
- (IsStatic ? Twine("`Symbols`")
- : Twine("`DynamicSymbols`")) +
- " for symbol table section '"
- << RawSec->Name << "'.\n";
+ reportError("cannot specify both `Content` and " +
+ (IsStatic ? Twine("`Symbols`") : Twine("`DynamicSymbols`")) +
+ " for symbol table section '" + RawSec->Name + "'");
if (RawSec->Size)
- WithColor::error() << "Cannot specify both `Size` and " +
- (IsStatic ? Twine("`Symbols`")
- : Twine("`DynamicSymbols`")) +
- " for symbol table section '"
- << RawSec->Name << "'.\n";
- exit(1);
+ reportError("cannot specify both `Size` and " +
+ (IsStatic ? Twine("`Symbols`") : Twine("`DynamicSymbols`")) +
+ " for symbol table section '" + RawSec->Name + "'");
+ return;
}
zero(SHeader);
@@ -509,10 +511,7 @@ void ELFState<ELFT>::initSymtabSectionHe
if (RawSec && !RawSec->Link.empty()) {
// If the Link field is explicitly defined in the document,
// we should use it.
- unsigned Index;
- if (!convertSectionIndex(SN2I, RawSec->Name, RawSec->Link, Index))
- return;
- SHeader.sh_link = Index;
+ SHeader.sh_link = toSectionIndex(RawSec->Link, RawSec->Name);
} else {
// When we describe the .dynsym section in the document explicitly, it is
// allowed to omit the "DynamicSymbols" tag. In this case .dynstr is not
@@ -549,7 +548,7 @@ void ELFState<ELFT>::initSymtabSectionHe
}
std::vector<Elf_Sym> Syms =
- toELFSymbols<ELFT>(SN2I, Symbols, IsStatic ? DotStrtab : DotDynstr);
+ toELFSymbols(Symbols, IsStatic ? DotStrtab : DotDynstr);
writeArrayData(OS, makeArrayRef(Syms));
SHeader.sh_size = arrayDataSize(makeArrayRef(Syms));
}
@@ -592,6 +591,11 @@ void ELFState<ELFT>::initStrtabSectionHe
SHeader.sh_addr = YAMLSec->Address;
}
+template <class ELFT> void ELFState<ELFT>::reportError(const Twine &Msg) {
+ WithColor::error() << Msg << "\n";
+ HasError = true;
+}
+
template <class ELFT>
void ELFState<ELFT>::setProgramHeaderLayout(std::vector<Elf_Phdr> &PHeaders,
std::vector<Elf_Shdr> &SHeaders) {
@@ -603,9 +607,9 @@ void ELFState<ELFT>::setProgramHeaderLay
for (const ELFYAML::SectionName &SecName : YamlPhdr.Sections) {
unsigned Index;
if (!SN2I.lookup(SecName.Section, Index)) {
- WithColor::error() << "Unknown section referenced: '" << SecName.Section
- << "' by program header.\n";
- exit(1);
+ reportError("unknown section referenced: '" + SecName.Section +
+ "' by program header");
+ continue;
}
Sections.push_back(&SHeaders[Index]);
}
@@ -668,7 +672,7 @@ void ELFState<ELFT>::setProgramHeaderLay
}
template <class ELFT>
-bool ELFState<ELFT>::writeSectionContent(
+void ELFState<ELFT>::writeSectionContent(
Elf_Shdr &SHeader, const ELFYAML::RawContentSection &Section,
ContiguousBlobAccumulator &CBA) {
raw_ostream &OS =
@@ -684,8 +688,6 @@ bool ELFState<ELFT>::writeSectionContent
if (Section.Info)
SHeader.sh_info = *Section.Info;
-
- return true;
}
static bool isMips64EL(const ELFYAML::Object &Doc) {
@@ -695,7 +697,7 @@ static bool isMips64EL(const ELFYAML::Ob
}
template <class ELFT>
-bool ELFState<ELFT>::writeSectionContent(
+void ELFState<ELFT>::writeSectionContent(
Elf_Shdr &SHeader, const ELFYAML::RelocationSection &Section,
ContiguousBlobAccumulator &CBA) {
assert((Section.Type == llvm::ELF::SHT_REL ||
@@ -710,26 +712,14 @@ bool ELFState<ELFT>::writeSectionContent
if (Section.Link.empty())
SHeader.sh_link = SN2I.get(".symtab");
- unsigned Index = 0;
- if (!Section.RelocatableSec.empty() &&
- !convertSectionIndex(SN2I, Section.Name, Section.RelocatableSec, Index))
- return false;
- SHeader.sh_info = Index;
+ if (!Section.RelocatableSec.empty())
+ SHeader.sh_info = toSectionIndex(Section.RelocatableSec, Section.Name);
auto &OS = CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
-
- const NameToIdxMap &SymMap = Section.Link == ".dynsym" ? DynSymN2I : SymN2I;
for (const auto &Rel : Section.Relocations) {
- unsigned SymIdx = 0;
- // If a relocation references a symbol, try to look one up in the symbol
- // table. If it is not there, treat the value as a symbol index.
- if (Rel.Symbol && !SymMap.lookup(*Rel.Symbol, SymIdx) &&
- !to_integer(*Rel.Symbol, SymIdx)) {
- WithColor::error() << "Unknown symbol referenced: '" << *Rel.Symbol
- << "' at YAML section '" << Section.Name << "'.\n";
- return false;
- }
-
+ unsigned SymIdx = Rel.Symbol ? toSymbolIndex(*Rel.Symbol, Section.Name,
+ Section.Link == ".dynsym")
+ : 0;
if (IsRela) {
Elf_Rela REntry;
zero(REntry);
@@ -745,11 +735,10 @@ bool ELFState<ELFT>::writeSectionContent
OS.write((const char *)&REntry, sizeof(REntry));
}
}
- return true;
}
template <class ELFT>
-bool ELFState<ELFT>::writeSectionContent(
+void ELFState<ELFT>::writeSectionContent(
Elf_Shdr &SHeader, const ELFYAML::SymtabShndxSection &Shndx,
ContiguousBlobAccumulator &CBA) {
raw_ostream &OS =
@@ -760,11 +749,10 @@ bool ELFState<ELFT>::writeSectionContent
SHeader.sh_entsize = Shndx.EntSize ? (uint64_t)*Shndx.EntSize : 4;
SHeader.sh_size = Shndx.Entries.size() * SHeader.sh_entsize;
- return true;
}
template <class ELFT>
-bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
+void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::Group &Section,
ContiguousBlobAccumulator &CBA) {
assert(Section.Type == llvm::ELF::SHT_GROUP &&
@@ -772,15 +760,8 @@ bool ELFState<ELFT>::writeSectionContent
SHeader.sh_entsize = 4;
SHeader.sh_size = SHeader.sh_entsize * Section.Members.size();
-
- unsigned SymIdx;
- if (!SymN2I.lookup(Section.Signature, SymIdx) &&
- !to_integer(Section.Signature, SymIdx)) {
- WithColor::error() << "Unknown symbol referenced: '" << Section.Signature
- << "' at YAML section '" << Section.Name << "'.\n";
- return false;
- }
- SHeader.sh_info = SymIdx;
+ SHeader.sh_info =
+ toSymbolIndex(Section.Signature, Section.Name, /*IsDynamic=*/false);
raw_ostream &OS =
CBA.getOSAndAlignedOffset(SHeader.sh_offset, SHeader.sh_addralign);
@@ -789,16 +770,14 @@ bool ELFState<ELFT>::writeSectionContent
unsigned int SectionIndex = 0;
if (Member.sectionNameOrType == "GRP_COMDAT")
SectionIndex = llvm::ELF::GRP_COMDAT;
- else if (!convertSectionIndex(SN2I, Section.Name, Member.sectionNameOrType,
- SectionIndex))
- return false;
+ else
+ SectionIndex = toSectionIndex(Member.sectionNameOrType, Section.Name);
support::endian::write<uint32_t>(OS, SectionIndex, ELFT::TargetEndianness);
}
- return true;
}
template <class ELFT>
-bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
+void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::SymverSection &Section,
ContiguousBlobAccumulator &CBA) {
raw_ostream &OS =
@@ -808,11 +787,10 @@ bool ELFState<ELFT>::writeSectionContent
SHeader.sh_entsize = Section.EntSize ? (uint64_t)*Section.EntSize : 2;
SHeader.sh_size = Section.Entries.size() * SHeader.sh_entsize;
- return true;
}
template <class ELFT>
-bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
+void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::VerdefSection &Section,
ContiguousBlobAccumulator &CBA) {
typedef typename ELFT::Verdef Elf_Verdef;
@@ -852,12 +830,10 @@ bool ELFState<ELFT>::writeSectionContent
SHeader.sh_size = Section.Entries.size() * sizeof(Elf_Verdef) +
AuxCnt * sizeof(Elf_Verdaux);
SHeader.sh_info = Section.Info;
-
- return true;
}
template <class ELFT>
-bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
+void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::VerneedSection &Section,
ContiguousBlobAccumulator &CBA) {
typedef typename ELFT::Verneed Elf_Verneed;
@@ -900,12 +876,10 @@ bool ELFState<ELFT>::writeSectionContent
SHeader.sh_size = Section.VerneedV.size() * sizeof(Elf_Verneed) +
AuxCnt * sizeof(Elf_Vernaux);
SHeader.sh_info = Section.Info;
-
- return true;
}
template <class ELFT>
-bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
+void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::MipsABIFlags &Section,
ContiguousBlobAccumulator &CBA) {
assert(Section.Type == llvm::ELF::SHT_MIPS_ABIFLAGS &&
@@ -929,12 +903,10 @@ bool ELFState<ELFT>::writeSectionContent
Flags.flags1 = Section.Flags1;
Flags.flags2 = Section.Flags2;
OS.write((const char *)&Flags, sizeof(Flags));
-
- return true;
}
template <class ELFT>
-bool ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
+void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
const ELFYAML::DynamicSection &Section,
ContiguousBlobAccumulator &CBA) {
typedef typename ELFT::uint uintX_t;
@@ -942,13 +914,10 @@ bool ELFState<ELFT>::writeSectionContent
assert(Section.Type == llvm::ELF::SHT_DYNAMIC &&
"Section type is not SHT_DYNAMIC");
- if (!Section.Entries.empty() && Section.Content) {
- WithColor::error()
- << "Cannot specify both raw content and explicit entries "
- "for dynamic section '"
- << Section.Name << "'.\n";
- return false;
- }
+ if (!Section.Entries.empty() && Section.Content)
+ reportError("cannot specify both raw content and explicit entries "
+ "for dynamic section '" +
+ Section.Name + "'");
if (Section.Content)
SHeader.sh_size = Section.Content->binary_size();
@@ -967,42 +936,34 @@ bool ELFState<ELFT>::writeSectionContent
}
if (Section.Content)
Section.Content->writeAsBinary(OS);
-
- return true;
}
-template <class ELFT> bool ELFState<ELFT>::buildSectionIndex() {
+template <class ELFT> void ELFState<ELFT>::buildSectionIndex() {
for (unsigned I = 0, E = Doc.Sections.size(); I != E; ++I) {
StringRef Name = Doc.Sections[I]->Name;
if (Name.empty())
continue;
DotShStrtab.add(dropUniqueSuffix(Name));
- if (!SN2I.addName(Name, I)) {
- WithColor::error() << "Repeated section name: '" << Name
- << "' at YAML section number " << I << ".\n";
- return false;
- }
+ if (!SN2I.addName(Name, I))
+ reportError("repeated section name: '" + Name +
+ "' at YAML section number " + Twine(I));
}
DotShStrtab.finalize();
- return true;
}
-static bool buildSymbolsMap(ArrayRef<ELFYAML::Symbol> V, NameToIdxMap &Map) {
- for (size_t I = 0, S = V.size(); I < S; ++I) {
- const ELFYAML::Symbol &Sym = V[I];
- if (Sym.Name.empty() || Map.addName(Sym.Name, I + 1))
- continue;
- WithColor::error() << "Repeated symbol name: '" << Sym.Name << "'.\n";
- return false;
- }
- return true;
-}
+template <class ELFT> void ELFState<ELFT>::buildSymbolIndexes() {
+ auto Build = [this](ArrayRef<ELFYAML::Symbol> V, NameToIdxMap &Map) {
+ for (size_t I = 0, S = V.size(); I < S; ++I) {
+ const ELFYAML::Symbol &Sym = V[I];
+ if (!Sym.Name.empty() && !Map.addName(Sym.Name, I + 1))
+ reportError("repeated symbol name: '" + Sym.Name + "'");
+ }
+ };
-template <class ELFT> bool ELFState<ELFT>::buildSymbolIndexes() {
- return buildSymbolsMap(Doc.Symbols, SymN2I) &&
- buildSymbolsMap(Doc.DynamicSymbols, DynSymN2I);
+ Build(Doc.Symbols, SymN2I);
+ Build(Doc.DynamicSymbols, DynSymN2I);
}
template <class ELFT> void ELFState<ELFT>::finalizeStrings() {
@@ -1043,8 +1004,8 @@ int ELFState<ELFT>::writeELF(raw_ostream
// sections that might want to use them.
State.finalizeStrings();
- if (!State.buildSectionIndex() || !State.buildSymbolIndexes())
- return 1;
+ State.buildSectionIndex();
+ State.buildSymbolIndexes();
std::vector<Elf_Phdr> PHeaders;
State.initProgramHeaders(PHeaders);
@@ -1056,12 +1017,14 @@ int ELFState<ELFT>::writeELF(raw_ostream
ContiguousBlobAccumulator CBA(SectionContentBeginOffset);
std::vector<Elf_Shdr> SHeaders;
- if (!State.initSectionHeaders(SHeaders, CBA))
- return 1;
+ State.initSectionHeaders(SHeaders, CBA);
// Now we can decide segment offsets
State.setProgramHeaderLayout(PHeaders, SHeaders);
+ if (State.HasError)
+ return 1;
+
State.writeELFHeader(CBA, OS);
writeArrayData(OS, makeArrayRef(PHeaders));
CBA.writeBlobToStream(OS);
Modified: llvm/trunk/test/tools/yaml2obj/duplicate-section-names.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/duplicate-section-names.test?rev=371380&r1=371379&r2=371380&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/duplicate-section-names.test (original)
+++ llvm/trunk/test/tools/yaml2obj/duplicate-section-names.test Mon Sep 9 02:43:03 2019
@@ -29,7 +29,8 @@ Sections:
## sections with equal names and suffixes.
# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=CASE2
-# CASE2: error: Repeated section name: '.foo [1]' at YAML section number 2.
+# CASE2: error: repeated section name: '.foo [1]' at YAML section number 2
+# CASE2: error: repeated section name: '.foo [1]' at YAML section number 3
--- !ELF
FileHeader:
@@ -42,13 +43,15 @@ Sections:
Type: SHT_PROGBITS
- Name: '.foo [1]'
Type: SHT_PROGBITS
+ - Name: '.foo [1]'
+ Type: SHT_PROGBITS
## Check that yaml2obj reports an error in case we have
## symbols without suffixes in the names and their
## names are equal.
# RUN: not yaml2obj --docnum=3 %s 2>&1 | FileCheck %s --check-prefix=CASE3
-# CASE3: error: Repeated section name: '.foo' at YAML section number 2.
+# CASE3: error: repeated section name: '.foo' at YAML section number 2
--- !ELF
FileHeader:
Modified: llvm/trunk/test/tools/yaml2obj/duplicate-symbol-names.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/duplicate-symbol-names.test?rev=371380&r1=371379&r2=371380&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/duplicate-symbol-names.test (original)
+++ llvm/trunk/test/tools/yaml2obj/duplicate-symbol-names.test Mon Sep 9 02:43:03 2019
@@ -21,7 +21,7 @@ Symbols:
## symbols with equal names and suffixes.
# RUN: not yaml2obj --docnum=2 %s 2>&1| FileCheck %s --check-prefix=CASE2
-# CASE2: error: Repeated symbol name: 'localfoo [1]'.
+# CASE2-COUNT-2: error: repeated symbol name: 'localfoo [1]'
--- !ELF
FileHeader:
@@ -32,13 +32,15 @@ FileHeader:
Symbols:
- Name: 'localfoo [1]'
- Name: 'localfoo [1]'
+ - Name: 'localfoo [1]'
## Check that yaml2obj reports an error when we have
## symbols without suffixes in the names and their
## names are equal.
# RUN: not yaml2obj --docnum=3 %s 2>&1| FileCheck %s --check-prefix=CASE3
-# CASE3: error: Repeated symbol name: 'localfoo'.
+# CASE3: error: repeated symbol name: 'localfoo'
+# CASE3: error: repeated symbol name: 'localfoo'
--- !ELF
FileHeader:
@@ -47,10 +49,9 @@ FileHeader:
Type: ET_REL
Machine: EM_X86_64
Symbols:
- - Name: localfoo
- Section: .text.foo.1
- - Name: localfoo
- Section: .text.foo.2
+ - Name: localfoo
+ - Name: localfoo
+ - Name: localfoo
## Check that yaml2obj can produce correct relocations that
## reference symbols with name suffixes.
Modified: llvm/trunk/test/tools/yaml2obj/dynamic-section-raw-content.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/dynamic-section-raw-content.yaml?rev=371380&r1=371379&r2=371380&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/dynamic-section-raw-content.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/dynamic-section-raw-content.yaml Mon Sep 9 02:43:03 2019
@@ -15,9 +15,6 @@
# RAW: Hex dump of section '.dynamic':
# RAW-NEXT: 0x00000000 01234567 89012345 67890000 00000000 {{.*}}
-# RUN: not yaml2obj --docnum=2 %s -o %t2 2>&1 | FileCheck %s --check-prefix=ERR
-# ERR: Cannot specify both raw content and explicit entries for dynamic section '.dynamic'.
-
--- !ELF
FileHeader:
Class: ELFCLASS64
@@ -29,6 +26,11 @@ Sections:
Type: SHT_DYNAMIC
Content: "01234567890123456789000000000000"
+# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=ERR
+
+# ERR: cannot specify both raw content and explicit entries for dynamic section '.dynamic1'
+# ERR: cannot specify both raw content and explicit entries for dynamic section '.dynamic2'
+
--- !ELF
FileHeader:
Class: ELFCLASS64
@@ -36,7 +38,13 @@ FileHeader:
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- - Name: .dynamic
+ - Name: .dynamic1
+ Type: SHT_DYNAMIC
+ Content: "0123456789"
+ Entries:
+ - Tag: DT_STRSZ
+ Value: 0
+ - Name: .dynamic2
Type: SHT_DYNAMIC
Content: "0123456789"
Entries:
Modified: llvm/trunk/test/tools/yaml2obj/dynamic-symbols.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/dynamic-symbols.yaml?rev=371380&r1=371379&r2=371380&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/dynamic-symbols.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/dynamic-symbols.yaml Mon Sep 9 02:43:03 2019
@@ -1,9 +1,10 @@
-# Ensures that implicitly added sections can be ordered within Sections.
-# RUN: yaml2obj %s -o %t
-# RUN: llvm-readobj --sections %t | FileCheck %s --check-prefix=SECTION
+## Ensures that implicitly added sections can be ordered within Sections.
+
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: llvm-readobj --sections %t1 | FileCheck %s --check-prefix=SECTION
# RUN: llvm-nm --dynamic %t | FileCheck %s --check-prefix=SYMBOL
-!ELF
+--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
@@ -39,3 +40,57 @@ DynamicSymbols:
# SYMBOL-DAG: d dynlocal
# SYMBOL-DAG: D dynglobal
# SYMBOL-DAG: V dynweak
+
+## Check we can use numeric values to refer to sections.
+
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: not llvm-readobj --dyn-symbols %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefix=NUM
+
+# NUM: Name: foo
+# NUM: Section:
+# NUM-SAME: .data (0x1)
+
+# NUM: Name: bar
+# NUM: Section:
+# NUM-SAME: .symtab (0x2)
+
+# NUM: error: '[[FILE]]': invalid section index: 255
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .data
+ Type: SHT_PROGBITS
+DynamicSymbols:
+ - Name: foo
+ Section: 1
+ - Name: bar
+ Section: 2
+ - Name: zed
+ Section: 0xff
+
+## Check we report errors when unknown sections are referenced by dynamic symbols.
+
+# RUN: not yaml2obj --docnum=3 %s 2>&1 | FileCheck -DFILE=%t3 %s --check-prefix=ERR
+
+# ERR: error: unknown section referenced: '.sec1' by YAML symbol 'foo'
+# ERR: error: unknown section referenced: '.sec2' by YAML symbol 'bar'
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .data
+ Type: SHT_PROGBITS
+DynamicSymbols:
+ - Name: foo
+ Section: .sec1
+ - Name: bar
+ Section: .sec2
Modified: llvm/trunk/test/tools/yaml2obj/dynsymtab-implicit-sections-size-content.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/dynsymtab-implicit-sections-size-content.yaml?rev=371380&r1=371379&r2=371380&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/dynsymtab-implicit-sections-size-content.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/dynsymtab-implicit-sections-size-content.yaml Mon Sep 9 02:43:03 2019
@@ -27,10 +27,12 @@ DynamicSymbols:
- Name: foo
Binding: STB_GLOBAL
-## Specifying both `Size` and symbols at the same time is not allowed.
-# RUN: not yaml2obj --docnum=2 %s -o %t2 2>&1 | FileCheck %s --check-prefix=CASE2
+## Specifying both `Size` and symbols at the same time is not allowed for .dynsym.
-# CASE2: error: Cannot specify both `Size` and `DynamicSymbols` for symbol table section '.dynsym'.
+# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --implicit-check-not=error --check-prefix=CASE2
+
+# CASE2: error: cannot specify both `Size` and `DynamicSymbols` for symbol table section '.dynsym'
+# CASE2: error: yaml2obj failed
--- !ELF
FileHeader:
@@ -42,14 +44,19 @@ Sections:
- Name: .dynsym
Type: SHT_DYNSYM
Size: 0x100
+ - Name: .dynsym2
+ Type: SHT_DYNSYM
+ Size: 0x100
DynamicSymbols:
- Name: foo
Binding: STB_GLOBAL
-## Specifying both `Content` and symbols at the same time is not allowed.
-# RUN: not yaml2obj --docnum=3 %s -o %t3 2>&1 | FileCheck %s --check-prefix=CASE3
+## Specifying both `Content` and symbols at the same time is not allowed for .dynsym.
-# CASE3: error: Cannot specify both `Content` and `DynamicSymbols` for symbol table section '.dynsym'.
+# RUN: not yaml2obj --docnum=3 %s 2>&1 | FileCheck %s --implicit-check-not=error --check-prefix=CASE3
+
+# CASE3: error: cannot specify both `Content` and `DynamicSymbols` for symbol table section '.dynsym'
+# CASE3: error: yaml2obj failed
--- !ELF
FileHeader:
@@ -61,6 +68,9 @@ Sections:
- Name: .dynsym
Type: SHT_DYNSYM
Content: "00"
+ - Name: .dynsym2
+ Type: SHT_DYNSYM
+ Content: "00"
DynamicSymbols:
- Name: foo
Binding: STB_GLOBAL
Modified: llvm/trunk/test/tools/yaml2obj/elf-comdat-broken-info.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/elf-comdat-broken-info.yaml?rev=371380&r1=371379&r2=371380&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-comdat-broken-info.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/elf-comdat-broken-info.yaml Mon Sep 9 02:43:03 2019
@@ -1,5 +1,7 @@
-# RUN: yaml2obj %s -o %t
-# RUN: llvm-readobj --sections %t | FileCheck %s
+## Check we are able to produce an SHT_GROUP section with a custom Info value (12345).
+
+# RUN: yaml2obj %s -o %t1
+# RUN: llvm-readobj --sections %t1 | FileCheck %s
--- !ELF
FileHeader:
@@ -15,7 +17,6 @@ Sections:
Members:
- SectionOrType: GRP_COMDAT
-## Check we are able to produce SHT_GROUP section with a custom Info value (12345).
# CHECK: Name: .group
# CHECK-NEXT: Type: SHT_GROUP
# CHECK-NEXT: Flags [
@@ -25,3 +26,30 @@ Sections:
# CHECK-NEXT: Size:
# CHECK-NEXT: Link:
# CHECK-NEXT: Info: 12345
+
+## Check we report multiple errors when multiple unknown symbols are referenced by SHT_GROUP sections.
+
+# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=ERR
+
+# ERR: error: unknown symbol referenced: 'foo' by YAML section '.group1'
+# ERR: error: unknown symbol referenced: 'bar' by YAML section '.group2'
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .group1
+ Type: SHT_GROUP
+ Link: .symtab
+ Info: foo
+ Members:
+ - SectionOrType: GRP_COMDAT
+ - Name: .group2
+ Type: SHT_GROUP
+ Link: .symtab
+ Info: bar
+ Members:
+ - SectionOrType: GRP_COMDAT
Added: llvm/trunk/test/tools/yaml2obj/elf-comdat-broken-members.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/elf-comdat-broken-members.yaml?rev=371380&view=auto
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-comdat-broken-members.yaml (added)
+++ llvm/trunk/test/tools/yaml2obj/elf-comdat-broken-members.yaml Mon Sep 9 02:43:03 2019
@@ -0,0 +1,22 @@
+## Check we report an error when SHT_GROUP references an unknown section in its member list.
+
+# RUN: not yaml2obj %s 2>&1 | FileCheck %s
+
+# CHECK: error: unknown section referenced: '.foo' by YAML section '.group'
+# CHECK: error: unknown section referenced: '.bar' by YAML section '.group'
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .group
+ Type: SHT_GROUP
+ Link: .symtab
+ Info: 0
+ Members:
+ - SectionOrType: GRP_COMDAT
+ - SectionOrType: .foo
+ - SectionOrType: .bar
Modified: llvm/trunk/test/tools/yaml2obj/elf-custom-null-section.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/elf-custom-null-section.yaml?rev=371380&r1=371379&r2=371380&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-custom-null-section.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/elf-custom-null-section.yaml Mon Sep 9 02:43:03 2019
@@ -130,7 +130,7 @@ Sections:
# RUN: not yaml2obj --docnum=6 %s -o %t6 2>&1 | FileCheck %s --check-prefix=CASE4
-# CASE4: error: Unknown section referenced: '.foo' at YAML section ''.
+# CASE4: error: unknown section referenced: '.foo' by YAML section ''
--- !ELF
FileHeader:
Modified: llvm/trunk/test/tools/yaml2obj/program-header.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/program-header.yaml?rev=371380&r1=371379&r2=371380&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/program-header.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/program-header.yaml Mon Sep 9 02:43:03 2019
@@ -80,15 +80,18 @@ ProgramHeaders:
## Check we do not allow referencing sections that do not exist.
# RUN: not yaml2obj --docnum=2 %s -o %t 2>&1 | FileCheck %s --check-prefix=ERR
-# ERR: error: Unknown section referenced: '.foo' by program header.
+
+# ERR: error: unknown section referenced: '.foo' by program header
+# ERR: error: unknown section referenced: '.bar' by program header
--- !ELF
FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_EXEC
- Machine: EM_X86_64
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
ProgramHeaders:
- Type: PT_LOAD
Sections:
- Section: .foo
+ - Section: .bar
Modified: llvm/trunk/test/tools/yaml2obj/reloc-sec-info.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/reloc-sec-info.yaml?rev=371380&r1=371379&r2=371380&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/reloc-sec-info.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/reloc-sec-info.yaml Mon Sep 9 02:43:03 2019
@@ -1,5 +1,5 @@
-# RUN: yaml2obj %s -o %t
-# RUN: llvm-readobj --sections %t | FileCheck %s
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: llvm-readobj --sections %t1 | FileCheck %s
# CHECK: Name: .rela.text
# CHECK-NEXT: Type: SHT_RELA
@@ -23,3 +23,31 @@ Sections:
Link: .symtab
Info: 12345
Relocations:
+
+## Check we report an error when a relocation section references an unknown section via its Info field.
+
+# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --implicit-check-not=error --check-prefix=ERR
+
+# ERR: error: unknown section referenced: '.unknown1' by YAML section '.foo'
+# ERR: error: unknown section referenced: '.unknown2' by YAML section '.bar'
+# ERR: error: yaml2obj failed
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .foo
+ Type: SHT_RELA
+ Info: .unknown1
+ Relocations:
+ - Name: .bar
+ Type: SHT_RELA
+ Info: .unknown2
+ Relocations:
+ - Name: .zed
+ Type: SHT_RELA
+ Info: 0xFF
+ Relocations:
Modified: llvm/trunk/test/tools/yaml2obj/relocation-missing-symbol.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/relocation-missing-symbol.yaml?rev=371380&r1=371379&r2=371380&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/relocation-missing-symbol.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/relocation-missing-symbol.yaml Mon Sep 9 02:43:03 2019
@@ -1,9 +1,12 @@
-# Show that yaml2obj rejects a symbol reference from a relocation if the symbol
-# does not exist.
+## Show that yaml2obj rejects a symbol reference from a relocation if the symbol
+## does not exist.
# RUN: not yaml2obj %s -o %t 2>&1 | FileCheck %s
-# CHECK: Unknown symbol referenced: 'does_not_exist' at YAML section '.rela.text'
+## Check we are able to report multiple errors.
+
+# CHECK: error: unknown symbol referenced: 'does_not_exist1' by YAML section '.rela.text'
+# CHECK: error: unknown symbol referenced: 'does_not_exist2' by YAML section '.rela.text'
--- !ELF
FileHeader:
@@ -21,4 +24,7 @@ Sections:
Relocations:
- Type: R_X86_64_PC32
Offset: 0
- Symbol: does_not_exist
+ Symbol: does_not_exist1
+ - Type: R_X86_64_PC32
+ Offset: 0
+ Symbol: does_not_exist2
Modified: llvm/trunk/test/tools/yaml2obj/section-link.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/section-link.yaml?rev=371380&r1=371379&r2=371380&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/section-link.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/section-link.yaml Mon Sep 9 02:43:03 2019
@@ -1,5 +1,5 @@
-# RUN: yaml2obj %s -o %t
-# RUN: llvm-readobj --sections %t | FileCheck %s
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: llvm-readobj --sections %t1 | FileCheck %s
# CHECK: Name: .text
# CHECK-NEXT: Type: SHT_PROGBITS
@@ -23,3 +23,24 @@ Sections:
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
Link: 12345
+
+## Check we report an error when an unknown section is referenced via a Link field.
+
+# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=ERR
+
+# ERR: error: unknown section referenced: '.unknown1' by YAML section '.foo'
+# ERR: error: unknown section referenced: '.unknown2' by YAML section '.bar'
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .foo
+ Type: SHT_PROGBITS
+ Link: .unknown1
+ - Name: .bar
+ Type: SHT_PROGBITS
+ Link: .unknown2
Modified: llvm/trunk/test/tools/yaml2obj/symtab-implicit-sections-size-content.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/symtab-implicit-sections-size-content.yaml?rev=371380&r1=371379&r2=371380&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/symtab-implicit-sections-size-content.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/symtab-implicit-sections-size-content.yaml Mon Sep 9 02:43:03 2019
@@ -28,7 +28,7 @@ Symbols:
## Specifying both `Size` and symbols at the same time is not allowed.
# RUN: not yaml2obj --docnum=2 %s -o %t2 2>&1 | FileCheck %s --check-prefix=CASE2
-# CASE2: error: Cannot specify both `Size` and `Symbols` for symbol table section '.symtab'.
+# CASE2: error: cannot specify both `Size` and `Symbols` for symbol table section '.symtab'
--- !ELF
FileHeader:
@@ -46,7 +46,7 @@ Symbols:
## Specifying both `Content` and symbols at the same time is not allowed.
# RUN: not yaml2obj --docnum=3 %s -o %t3 2>&1 | FileCheck %s --check-prefix=CASE3
-# CASE3: error: Cannot specify both `Content` and `Symbols` for symbol table section '.symtab'.
+# CASE3: error: cannot specify both `Content` and `Symbols` for symbol table section '.symtab'
--- !ELF
FileHeader:
More information about the llvm-commits
mailing list