@@ -41,11 +41,10 @@ class EhReader {
41
41
bool hasLSDA ();
42
42
43
43
private:
44
- template <class P > void failOn (const P *loc, const Twine &msg) {
44
+ template <class P > void errOn (const P *loc, const Twine &msg) {
45
45
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 ());
49
48
}
50
49
51
50
uint8_t readByte ();
@@ -62,24 +61,29 @@ class EhReader {
62
61
63
62
// Read a byte and advance D by one byte.
64
63
uint8_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
+ }
67
68
uint8_t b = d.front ();
68
69
d = d.slice (1 );
69
70
return b;
70
71
}
71
72
72
73
void EhReader::skipBytes (size_t count) {
73
74
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);
76
78
}
77
79
78
80
// Read a null-terminated string.
79
81
StringRef EhReader::readString () {
80
82
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
+ }
83
87
StringRef s = toStringRef (d.slice (0 , end - d.begin ()));
84
88
d = d.slice (s.size () + 1 );
85
89
return s;
@@ -97,7 +101,7 @@ void EhReader::skipLeb128() {
97
101
if ((val & 0x80 ) == 0 )
98
102
return ;
99
103
}
100
- failOn (errPos, " corrupted CIE (failed to read LEB128)" );
104
+ errOn (errPos, " corrupted CIE (failed to read LEB128)" );
101
105
}
102
106
103
107
static size_t getAugPSize (Ctx &ctx, unsigned enc) {
@@ -121,12 +125,12 @@ static size_t getAugPSize(Ctx &ctx, unsigned enc) {
121
125
void EhReader::skipAugP () {
122
126
uint8_t enc = readByte ();
123
127
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" );
125
129
size_t size = getAugPSize (isec->getCtx (), enc);
126
130
if (size == 0 )
127
- failOn (d.data () - 1 , " unknown FDE encoding" );
131
+ return errOn (d.data () - 1 , " unknown FDE encoding" );
128
132
if (size >= d.size ())
129
- failOn (d.data () - 1 , " corrupted CIE" );
133
+ return errOn (d.data () - 1 , " corrupted CIE" );
130
134
d = d.slice (size);
131
135
}
132
136
@@ -141,9 +145,11 @@ bool elf::hasLSDA(const EhSectionPiece &p) {
141
145
StringRef EhReader::getAugmentation () {
142
146
skipBytes (8 );
143
147
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
+ }
147
153
148
154
StringRef aug = readString ();
149
155
@@ -174,8 +180,10 @@ uint8_t EhReader::getFdeEncoding() {
174
180
readByte ();
175
181
else if (c == ' P' )
176
182
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
+ }
179
187
}
180
188
return DW_EH_PE_absptr;
181
189
}
@@ -191,8 +199,10 @@ bool EhReader::hasLSDA() {
191
199
skipAugP ();
192
200
else if (c == ' R' )
193
201
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
+ }
196
206
}
197
207
return false ;
198
208
}
0 commit comments