@@ -41,11 +41,10 @@ class EhReader {
4141 bool hasLSDA ();
4242
4343private:
44- template <class P > void failOn (const P *loc, const Twine &msg) {
44+ template <class P > void errOn (const P *loc, const Twine &msg) {
4545 Ctx &ctx = isec->file ->ctx ;
46- Fatal (ctx) << " corrupted .eh_frame: " << msg << " \n >>> defined in "
47- << isec->getObjMsg ((const uint8_t *)loc -
48- isec->content ().data ());
46+ Err (ctx) << " corrupted .eh_frame: " << msg << " \n >>> defined in "
47+ << isec->getObjMsg ((const uint8_t *)loc - isec->content ().data ());
4948 }
5049
5150 uint8_t readByte ();
@@ -62,24 +61,29 @@ class EhReader {
6261
6362// Read a byte and advance D by one byte.
6463uint8_t EhReader::readByte () {
65- if (d.empty ())
66- failOn (d.data (), " unexpected end of CIE" );
64+ if (d.empty ()) {
65+ errOn (d.data (), " unexpected end of CIE" );
66+ return 0 ;
67+ }
6768 uint8_t b = d.front ();
6869 d = d.slice (1 );
6970 return b;
7071}
7172
7273void EhReader::skipBytes (size_t count) {
7374 if (d.size () < count)
74- failOn (d.data (), " CIE is too small" );
75- d = d.slice (count);
75+ errOn (d.data (), " CIE is too small" );
76+ else
77+ d = d.slice (count);
7678}
7779
7880// Read a null-terminated string.
7981StringRef EhReader::readString () {
8082 const uint8_t *end = llvm::find (d, ' \0 ' );
81- if (end == d.end ())
82- failOn (d.data (), " corrupted CIE (failed to read string)" );
83+ if (end == d.end ()) {
84+ errOn (d.data (), " corrupted CIE (failed to read string)" );
85+ return {};
86+ }
8387 StringRef s = toStringRef (d.slice (0 , end - d.begin ()));
8488 d = d.slice (s.size () + 1 );
8589 return s;
@@ -97,7 +101,7 @@ void EhReader::skipLeb128() {
97101 if ((val & 0x80 ) == 0 )
98102 return ;
99103 }
100- failOn (errPos, " corrupted CIE (failed to read LEB128)" );
104+ errOn (errPos, " corrupted CIE (failed to read LEB128)" );
101105}
102106
103107static size_t getAugPSize (Ctx &ctx, unsigned enc) {
@@ -121,12 +125,12 @@ static size_t getAugPSize(Ctx &ctx, unsigned enc) {
121125void EhReader::skipAugP () {
122126 uint8_t enc = readByte ();
123127 if ((enc & 0xf0 ) == DW_EH_PE_aligned)
124- failOn (d.data () - 1 , " DW_EH_PE_aligned encoding is not supported" );
128+ return errOn (d.data () - 1 , " DW_EH_PE_aligned encoding is not supported" );
125129 size_t size = getAugPSize (isec->getCtx (), enc);
126130 if (size == 0 )
127- failOn (d.data () - 1 , " unknown FDE encoding" );
131+ return errOn (d.data () - 1 , " unknown FDE encoding" );
128132 if (size >= d.size ())
129- failOn (d.data () - 1 , " corrupted CIE" );
133+ return errOn (d.data () - 1 , " corrupted CIE" );
130134 d = d.slice (size);
131135}
132136
@@ -141,9 +145,11 @@ bool elf::hasLSDA(const EhSectionPiece &p) {
141145StringRef EhReader::getAugmentation () {
142146 skipBytes (8 );
143147 int version = readByte ();
144- if (version != 1 && version != 3 )
145- failOn (d.data () - 1 ,
146- " FDE version 1 or 3 expected, but got " + Twine (version));
148+ if (version != 1 && version != 3 ) {
149+ errOn (d.data () - 1 ,
150+ " FDE version 1 or 3 expected, but got " + Twine (version));
151+ return {};
152+ }
147153
148154 StringRef aug = readString ();
149155
@@ -174,8 +180,10 @@ uint8_t EhReader::getFdeEncoding() {
174180 readByte ();
175181 else if (c == ' P' )
176182 skipAugP ();
177- else if (c != ' B' && c != ' S' && c != ' G' )
178- failOn (aug.data (), " unknown .eh_frame augmentation string: " + aug);
183+ else if (c != ' B' && c != ' S' && c != ' G' ) {
184+ errOn (aug.data (), " unknown .eh_frame augmentation string: " + aug);
185+ break ;
186+ }
179187 }
180188 return DW_EH_PE_absptr;
181189}
@@ -191,8 +199,10 @@ bool EhReader::hasLSDA() {
191199 skipAugP ();
192200 else if (c == ' R' )
193201 readByte ();
194- else if (c != ' B' && c != ' S' && c != ' G' )
195- failOn (aug.data (), " unknown .eh_frame augmentation string: " + aug);
202+ else if (c != ' B' && c != ' S' && c != ' G' ) {
203+ errOn (aug.data (), " unknown .eh_frame augmentation string: " + aug);
204+ break ;
205+ }
196206 }
197207 return false ;
198208}
0 commit comments