@@ -115,12 +115,13 @@ template <class ELFT> class ELFState {
115
115
ELFYAML::Object &Doc;
116
116
117
117
bool HasError = false ;
118
+ yaml::ErrorHandler ErrHandler;
119
+ void reportError (const Twine &Msg);
118
120
119
121
std::vector<Elf_Sym> toELFSymbols (ArrayRef<ELFYAML::Symbol> Symbols,
120
122
const StringTableBuilder &Strtab);
121
123
unsigned toSectionIndex (StringRef S, StringRef LocSec, StringRef LocSym = " " );
122
124
unsigned toSymbolIndex (StringRef S, StringRef LocSec, bool IsDynamic);
123
- void reportError (const Twine &Msg);
124
125
125
126
void buildSectionIndex ();
126
127
void buildSymbolIndexes ();
@@ -166,9 +167,11 @@ template <class ELFT> class ELFState {
166
167
void writeSectionContent (Elf_Shdr &SHeader,
167
168
const ELFYAML::DynamicSection &Section,
168
169
ContiguousBlobAccumulator &CBA);
169
- ELFState (ELFYAML::Object &D);
170
+ ELFState (ELFYAML::Object &D, yaml::ErrorHandler EH);
171
+
170
172
public:
171
- static bool writeELF (raw_ostream &OS, ELFYAML::Object &Doc);
173
+ static bool writeELF (raw_ostream &OS, ELFYAML::Object &Doc,
174
+ yaml::ErrorHandler EH);
172
175
};
173
176
} // end anonymous namespace
174
177
@@ -182,7 +185,9 @@ template <class T> static void writeArrayData(raw_ostream &OS, ArrayRef<T> A) {
182
185
183
186
template <class T > static void zero (T &Obj) { memset (&Obj, 0 , sizeof (Obj)); }
184
187
185
- template <class ELFT > ELFState<ELFT>::ELFState(ELFYAML::Object &D) : Doc(D) {
188
+ template <class ELFT >
189
+ ELFState<ELFT>::ELFState(ELFYAML::Object &D, yaml::ErrorHandler EH)
190
+ : Doc(D), ErrHandler(EH) {
186
191
StringSet<> DocSections;
187
192
for (std::unique_ptr<ELFYAML::Section> &D : Doc.Sections )
188
193
if (!D->Name .empty ())
@@ -592,7 +597,7 @@ void ELFState<ELFT>::initStrtabSectionHeader(Elf_Shdr &SHeader, StringRef Name,
592
597
}
593
598
594
599
template <class ELFT > void ELFState<ELFT>::reportError(const Twine &Msg) {
595
- WithColor::error () << Msg << " \n " ;
600
+ ErrHandler ( Msg) ;
596
601
HasError = true ;
597
602
}
598
603
@@ -983,8 +988,9 @@ template <class ELFT> void ELFState<ELFT>::finalizeStrings() {
983
988
}
984
989
985
990
template <class ELFT >
986
- bool ELFState<ELFT>::writeELF(raw_ostream &OS, ELFYAML::Object &Doc) {
987
- ELFState<ELFT> State (Doc);
991
+ bool ELFState<ELFT>::writeELF(raw_ostream &OS, ELFYAML::Object &Doc,
992
+ yaml::ErrorHandler EH) {
993
+ ELFState<ELFT> State (Doc, EH);
988
994
989
995
// Finalize .strtab and .dynstr sections. We do that early because want to
990
996
// finalize the string table builders before writing the content of the
@@ -1022,17 +1028,17 @@ bool ELFState<ELFT>::writeELF(raw_ostream &OS, ELFYAML::Object &Doc) {
1022
1028
namespace llvm {
1023
1029
namespace yaml {
1024
1030
1025
- bool yaml2elf (llvm::ELFYAML::Object &Doc, raw_ostream &Out) {
1031
+ bool yaml2elf (llvm::ELFYAML::Object &Doc, raw_ostream &Out, ErrorHandler EH ) {
1026
1032
bool IsLE = Doc.Header .Data == ELFYAML::ELF_ELFDATA (ELF::ELFDATA2LSB);
1027
1033
bool Is64Bit = Doc.Header .Class == ELFYAML::ELF_ELFCLASS (ELF::ELFCLASS64);
1028
1034
if (Is64Bit) {
1029
1035
if (IsLE)
1030
- return ELFState<object::ELF64LE>::writeELF (Out, Doc);
1031
- return ELFState<object::ELF64BE>::writeELF (Out, Doc);
1036
+ return ELFState<object::ELF64LE>::writeELF (Out, Doc, EH );
1037
+ return ELFState<object::ELF64BE>::writeELF (Out, Doc, EH );
1032
1038
}
1033
1039
if (IsLE)
1034
- return ELFState<object::ELF32LE>::writeELF (Out, Doc);
1035
- return ELFState<object::ELF32BE>::writeELF (Out, Doc);
1040
+ return ELFState<object::ELF32LE>::writeELF (Out, Doc, EH );
1041
+ return ELFState<object::ELF32BE>::writeELF (Out, Doc, EH );
1036
1042
}
1037
1043
1038
1044
} // namespace yaml
0 commit comments