@@ -81,7 +81,7 @@ typedef enum ElfSymbolType {
8181
8282// ---------------------------------------------------------------------------
8383// Parsed records. Strings point into the file's loaded byte buffer —
84- // they are valid as long as the `ElfFile ` is alive.
84+ // they are valid as long as the `Elf ` is alive.
8585// ---------------------------------------------------------------------------
8686
8787///
@@ -102,7 +102,7 @@ typedef struct ElfHeader {
102102
103103///
104104/// Decoded section header. `name` is borrowed from the file's
105- /// `.shstrtab` and stays valid until `ElfFileDeinit `.
105+ /// `.shstrtab` and stays valid until `ElfDeinit `.
106106///
107107typedef struct ElfSection {
108108 const char * name ;
@@ -134,19 +134,19 @@ typedef Vec(ElfSymbol) ElfSymbols;
134134
135135///
136136/// Parsed ELF file. Holds the raw bytes plus decoded indices into them.
137- /// Three construction paths, all of which leave the `ElfFile ` in the
137+ /// Three construction paths, all of which leave the `Elf ` in the
138138/// same lifecycle state: parser owns the bytes, parser frees them on
139- /// `ElfFileDeinit `. There is no "borrowed buffer" mode -- the L / R
139+ /// `ElfDeinit `. There is no "borrowed buffer" mode -- the L / R
140140/// split below mirrors `VecInsertL` / `VecInsertR`:
141141///
142- /// `ElfFileOpen ` — reads a file from disk; parser owns
142+ /// `ElfOpen ` — reads a file from disk; parser owns
143143/// the resulting buffer end-to-end.
144- /// `ElfFileOpenFromMemory ` — **L**: takes ownership of the
144+ /// `ElfOpenFromMemory ` — **L**: takes ownership of the
145145/// caller's `(data, data_size)`. Caller
146146/// must not free or touch `data`
147147/// afterwards. `alloc` MUST be the
148148/// allocator that produced `data`.
149- /// `ElfFileOpenFromMemoryCopy ` — **R**: allocates internally through
149+ /// `ElfOpenFromMemoryCopy ` — **R**: allocates internally through
150150/// `alloc`, copies the caller's bytes
151151/// in, and never retains the caller's
152152/// pointer. Caller's buffer is
@@ -174,7 +174,7 @@ typedef Vec(ElfSymbol) ElfSymbols;
174174/// - debuglink_crc : CRC32 of the expected sidecar contents
175175/// (validated by the resolver before use).
176176///
177- typedef struct ElfFile {
177+ typedef struct Elf {
178178 Buf data ;
179179 ElfHeader header ;
180180 ElfSections sections ;
@@ -184,40 +184,38 @@ typedef struct ElfFile {
184184 u32 build_id_size ;
185185 const char * debuglink_name ;
186186 u32 debuglink_crc ;
187- } ElfFile ;
187+ } Elf ;
188188
189189///
190190/// Open and parse an ELF file from disk.
191191///
192192/// out[out] : Populated on success.
193193/// path[in] : Filesystem path. Prefer `Str *`; `const char *` accepted.
194194/// alloc[in] : Allocator for the read-in byte buffer and the section /
195- /// symbol vectors. Must outlive the `ElfFile `.
195+ /// symbol vectors. Must outlive the `Elf `.
196196///
197197/// SUCCESS : Returns true; `out` owns the read-in buffer and will free
198- /// it on `ElfFileDeinit `.
198+ /// it on `ElfDeinit `.
199199/// FAILURE : Returns false; logs the failing step (open / read / magic /
200200/// class / decoding). `out` is left zeroed.
201201///
202202/// TAGS: Parser, ELF, File
203203///
204- bool elf_file_open ( ElfFile * out , const char * path , Allocator * alloc );
205- #define ElfFileOpen (...) MISRA_OVERLOAD(ElfFileOpen , __VA_ARGS__)
206- #define ElfFileOpen_2 (out , path ) \
204+ bool elf_open ( Elf * out , const char * path , Allocator * alloc );
205+ #define ElfOpen (...) MISRA_OVERLOAD(ElfOpen , __VA_ARGS__)
206+ #define ElfOpen_2 (out , path ) \
207207 _Generic( \
208208 (path), \
209- Str *: elf_file_open((out), ((Str *)(path))->data, MisraScope), \
210- const Str *: elf_file_open((out), ((const Str *)(path))->data, MisraScope), \
211- char *: elf_file_open((out), (const char *)(path), MisraScope), \
212- const char *: elf_file_open((out), (const char *)(path), MisraScope) \
209+ Str *: elf_open((out), ((Str *)(path))->data, MisraScope), \
210+ char *: elf_open((out), (const char *)(path), MisraScope), \
211+ const char *: elf_open((out), (const char *)(path), MisraScope) \
213212 )
214- #define ElfFileOpen_3 (out , path , alloc ) \
213+ #define ElfOpen_3 (out , path , alloc ) \
215214 _Generic( \
216215 (path), \
217- Str *: elf_file_open((out), ((Str *)(path))->data, ALLOCATOR_OF(alloc)), \
218- const Str *: elf_file_open((out), ((const Str *)(path))->data, ALLOCATOR_OF(alloc)), \
219- char *: elf_file_open((out), (const char *)(path), ALLOCATOR_OF(alloc)), \
220- const char *: elf_file_open((out), (const char *)(path), ALLOCATOR_OF(alloc)) \
216+ Str *: elf_open((out), ((Str *)(path))->data, ALLOCATOR_OF(alloc)), \
217+ char *: elf_open((out), (const char *)(path), ALLOCATOR_OF(alloc)), \
218+ const char *: elf_open((out), (const char *)(path), ALLOCATOR_OF(alloc)) \
221219 )
222220
223221///
@@ -228,14 +226,14 @@ bool elf_file_open(ElfFile *out, const char *path, Allocator *alloc);
228226/// internally and zeroes the caller's `*in` so any post-call use sees
229227/// an empty Buf instead of a stale alias. The parser then owns the
230228/// bytes and the buffer's allocator; both are released by
231- /// `ElfFileDeinit `. The zero-on-take invariant holds on both success
229+ /// `ElfDeinit `. The zero-on-take invariant holds on both success
232230/// and failure -- on parse failure the parser still consumed the Buf,
233231/// just frees it through the carried allocator before returning.
234232///
235233/// USAGE:
236234/// Buf buf = BufInit(&alloc);
237235/// FileRead(&f, &buf);
238- /// ElfFileOpenFromMemory (&elf, &buf);
236+ /// ElfOpenFromMemory (&elf, &buf);
239237/// // buf is now {NULL, 0, 0, NULL} -- safe to drop on stack.
240238///
241239/// out[out] : Populated on success.
@@ -249,8 +247,8 @@ bool elf_file_open(ElfFile *out, const char *path, Allocator *alloc);
249247///
250248/// TAGS: Parser, ELF, Memory, Ownership
251249///
252- bool elf_file_open_from_memory ( ElfFile * out , Buf * in );
253- #define ElfFileOpenFromMemory (out , in ) elf_file_open_from_memory ((out), (in))
250+ bool elf_open_from_memory ( Elf * out , Buf * in );
251+ #define ElfOpenFromMemory (out , in ) elf_open_from_memory ((out), (in))
254252
255253///
256254/// Parse an ELF object from an in-memory byte range -- **R-value /
@@ -265,29 +263,28 @@ bool elf_file_open_from_memory(ElfFile *out, Buf *in);
265263/// data[in] : Raw ELF bytes. Read-only here; caller keeps them.
266264/// data_size[in] : Length of `data` in bytes.
267265/// alloc[in] : Allocator for the internal copy and the section /
268- /// symbol vectors. Must outlive the `ElfFile `.
266+ /// symbol vectors. Must outlive the `Elf `.
269267///
270268/// SUCCESS : Returns true; `out` owns an independent copy of `data`.
271269/// FAILURE : Returns false; logs the failing step. `out` is left
272270/// zeroed and the caller's `data` is untouched.
273271///
274272/// TAGS: Parser, ELF, Memory, Copy
275273///
276- bool elf_file_open_from_memory_copy (ElfFile * out , const u8 * data , size data_size , Allocator * alloc );
277- #define ElfFileOpenFromMemoryCopy (...) MISRA_OVERLOAD(ElfFileOpenFromMemoryCopy, __VA_ARGS__)
278- #define ElfFileOpenFromMemoryCopy_3 (out , data , data_size ) \
279- elf_file_open_from_memory_copy((out), (data), (data_size), MisraScope)
280- #define ElfFileOpenFromMemoryCopy_4 (out , data , data_size , alloc ) \
281- elf_file_open_from_memory_copy((out), (data), (data_size), ALLOCATOR_OF(alloc))
274+ bool elf_open_from_memory_copy (Elf * out , const u8 * data , size data_size , Allocator * alloc );
275+ #define ElfOpenFromMemoryCopy (...) MISRA_OVERLOAD(ElfOpenFromMemoryCopy, __VA_ARGS__)
276+ #define ElfOpenFromMemoryCopy_3 (out , data , data_size ) elf_open_from_memory_copy((out), (data), (data_size), MisraScope)
277+ #define ElfOpenFromMemoryCopy_4 (out , data , data_size , alloc ) \
278+ elf_open_from_memory_copy((out), (data), (data_size), ALLOCATOR_OF(alloc))
282279
283280///
284- /// Release storage owned by an `ElfFile `. Frees the byte buffer
281+ /// Release storage owned by an `Elf `. Frees the byte buffer
285282/// through `allocator` and tears down the section / symbol vectors.
286- /// All three `ElfFileOpen *` constructors leave the parser as the
283+ /// All three `ElfOpen *` constructors leave the parser as the
287284/// sole owner of `data`, so this is unconditional. Safe to call on
288285/// a zeroed struct.
289286///
290- void ElfFileDeinit ( ElfFile * self );
287+ void ElfDeinit ( Elf * self );
291288
292289///
293290/// Look up the symbol whose `[value, value+size)` range contains
@@ -302,16 +299,16 @@ void ElfFileDeinit(ElfFile *self);
302299/// vaddr[in] : Virtual address to resolve.
303300///
304301/// SUCCESS : Returns a pointer to the matching `ElfSymbol`. The pointer
305- /// is valid until `ElfFileDeinit `.
302+ /// is valid until `ElfDeinit `.
306303/// FAILURE : Returns NULL if no symbol covers `vaddr`.
307304///
308305/// TAGS: Parser, ELF, Symbol
309306///
310- const ElfSymbol * ElfFileResolveAddress (const ElfFile * self , u64 vaddr );
307+ const ElfSymbol * ElfResolveAddress (const Elf * self , u64 vaddr );
311308
312309///
313310/// Find a section by name (first match). Returns NULL if absent.
314311///
315- const ElfSection * ElfFileFindSection (const ElfFile * self , const char * name );
312+ const ElfSection * ElfFindSection (const Elf * self , const char * name );
316313
317314#endif // MISRA_PARSERS_ELF_H
0 commit comments