@@ -115,12 +115,13 @@ template <class ELFT> class ELFState {
115115 ELFYAML::Object &Doc;
116116
117117 bool HasError = false ;
118+ yaml::ErrorHandler ErrHandler;
119+ void reportError (const Twine &Msg);
118120
119121 std::vector<Elf_Sym> toELFSymbols (ArrayRef<ELFYAML::Symbol> Symbols,
120122 const StringTableBuilder &Strtab);
121123 unsigned toSectionIndex (StringRef S, StringRef LocSec, StringRef LocSym = " " );
122124 unsigned toSymbolIndex (StringRef S, StringRef LocSec, bool IsDynamic);
123- void reportError (const Twine &Msg);
124125
125126 void buildSectionIndex ();
126127 void buildSymbolIndexes ();
@@ -166,9 +167,11 @@ template <class ELFT> class ELFState {
166167 void writeSectionContent (Elf_Shdr &SHeader,
167168 const ELFYAML::DynamicSection &Section,
168169 ContiguousBlobAccumulator &CBA);
169- ELFState (ELFYAML::Object &D);
170+ ELFState (ELFYAML::Object &D, yaml::ErrorHandler EH);
171+
170172public:
171- static bool writeELF (raw_ostream &OS, ELFYAML::Object &Doc);
173+ static bool writeELF (raw_ostream &OS, ELFYAML::Object &Doc,
174+ yaml::ErrorHandler EH);
172175};
173176} // end anonymous namespace
174177
@@ -182,7 +185,9 @@ template <class T> static void writeArrayData(raw_ostream &OS, ArrayRef<T> A) {
182185
183186template <class T > static void zero (T &Obj) { memset (&Obj, 0 , sizeof (Obj)); }
184187
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) {
186191 StringSet<> DocSections;
187192 for (std::unique_ptr<ELFYAML::Section> &D : Doc.Sections )
188193 if (!D->Name .empty ())
@@ -592,7 +597,7 @@ void ELFState<ELFT>::initStrtabSectionHeader(Elf_Shdr &SHeader, StringRef Name,
592597}
593598
594599template <class ELFT > void ELFState<ELFT>::reportError(const Twine &Msg) {
595- WithColor::error () << Msg << " \n " ;
600+ ErrHandler ( Msg) ;
596601 HasError = true ;
597602}
598603
@@ -983,8 +988,9 @@ template <class ELFT> void ELFState<ELFT>::finalizeStrings() {
983988}
984989
985990template <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);
988994
989995 // Finalize .strtab and .dynstr sections. We do that early because want to
990996 // 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) {
10221028namespace llvm {
10231029namespace yaml {
10241030
1025- bool yaml2elf (llvm::ELFYAML::Object &Doc, raw_ostream &Out) {
1031+ bool yaml2elf (llvm::ELFYAML::Object &Doc, raw_ostream &Out, ErrorHandler EH ) {
10261032 bool IsLE = Doc.Header .Data == ELFYAML::ELF_ELFDATA (ELF::ELFDATA2LSB);
10271033 bool Is64Bit = Doc.Header .Class == ELFYAML::ELF_ELFCLASS (ELF::ELFCLASS64);
10281034 if (Is64Bit) {
10291035 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 );
10321038 }
10331039 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 );
10361042}
10371043
10381044} // namespace yaml
0 commit comments