Skip to content

Commit 3422281

Browse files
committed
Support for Mach-O univeral-binary reading
DO NOT USE THIS COMMIT. Shortly the many debugging printf lines will be removed. modified: src/lib/libdwarf/CMakeLists.txt modified: src/lib/libdwarf/Makefile.am modified: src/lib/libdwarf/dwarf_abbrev.h modified: src/lib/libdwarf/dwarf_alloc.h modified: src/lib/libdwarf/dwarf_errmsg_list.h modified: src/lib/libdwarf/dwarf_generic_init.c modified: src/lib/libdwarf/dwarf_macho_loader.h modified: src/lib/libdwarf/dwarf_machoread.c modified: src/lib/libdwarf/dwarf_machoread.h modified: src/lib/libdwarf/dwarf_object_detector.c modified: src/lib/libdwarf/dwarf_object_detector.h modified: src/lib/libdwarf/dwarf_opaque.h
1 parent ce74123 commit 3422281

12 files changed

+653
-39
lines changed

src/lib/libdwarf/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ dwarf_tied_decls.h
6161
dwarf_tsearch.h
6262
dwarf_setup_sections.h
6363
dwarf_str_offsets.h
64+
dwarf_universal.h
6465
dwarf_util.h
6566
dwarf_xu_index.h libdwarf_private.h
6667
dwarf_macho_loader.h

src/lib/libdwarf/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ dwarf_tied.c \
109109
dwarf_tied_decls.h \
110110
dwarf_tsearchhash.c \
111111
dwarf_tsearch.h \
112+
dwarf_universal.h \
112113
dwarf_util.c \
113114
dwarf_util.h \
114115
dwarf_xu_index.c \

src/lib/libdwarf/dwarf_abbrev.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
2828
*/
2929

30+
#ifndef DWARF_ABBREV_H
31+
#define DWARF_ABBREV_H
32+
33+
#ifdef __cplusplus
34+
extern "C" {
35+
#endif /* __cplusplus */
36+
3037
/* In a given CU, one of these is (eventually) set up
3138
for every abbreviation we need to find (and for all
3239
those earlier in the abbreviations for that CU).
@@ -67,3 +74,9 @@ int _dwarf_count_abbrev_entries(Dwarf_Debug dbg,
6774
Dwarf_Unsigned *abbrev_implicit_const_count_out,
6875
Dwarf_Byte_Ptr *abbrev_ptr_out,
6976
Dwarf_Error *error);
77+
78+
#ifdef __cplusplus
79+
}
80+
#endif /* __cplusplus */
81+
82+
#endif /* DWARF_ABBREV_H */

src/lib/libdwarf/dwarf_alloc.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
Fifth Floor, Boston MA 02110-1301, USA.
2727
*/
2828

29+
#ifndef DWARF_ALLOC_H
30+
#define DWARF_ALLOC_H
31+
32+
#ifdef __cplusplus
33+
extern "C" {
34+
#endif /* __cplusplus */
35+
2936
/* #define DWARF_SIMPLE_MALLOC 1 */
3037

3138
char * _dwarf_get_alloc(Dwarf_Debug, Dwarf_Small, Dwarf_Unsigned);
@@ -43,3 +50,9 @@ void _dwarf_error_destructor(void *);
4350
void _dwarf_add_to_static_err_list(Dwarf_Error err);
4451
void _dwarf_flush_static_error_list(void);
4552
void _dwarf_free_static_errlist(void);
53+
54+
#ifdef __cplusplus
55+
}
56+
#endif /* __cplusplus */
57+
58+
#endif /* DWARF_ALLOC_H */

src/lib/libdwarf/dwarf_errmsg_list.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ static const char _dwarf_errmsgs[DW_DLE_LAST+1][DW_MAX_MSG_LEN] = {
682682
{"DW_DLE_LINE_COUNT_WRONG(500) A count in a line table is "
683683
"not valid. Corrupt data."},
684684
{"DW_DLE_ARITHMETIC_OVERFLOW(501) Arithmetic overflow. "
685-
" Corrupt Dwarf." }
685+
" Corrupt Dwarf." },
686+
{" DW_DLE_UNIVERSAL_BINARY_ERROR(502) Error reading Mach-O "
687+
"uninversal binary head. Corrupt Mach-O object." }
686688
};
687689
#endif /* DWARF_ERRMSG_LIST_H */

src/lib/libdwarf/dwarf_generic_init.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ set_global_paths_init(Dwarf_Debug dbg, Dwarf_Error* error)
125125
}
126126

127127
/* New in December 2018. */
128+
int dwarf_init_path_a(const char *path,
129+
char * true_path_out_buffer,
130+
unsigned true_path_bufferlen,
131+
unsigned groupnumber,
132+
unsigned universalnumber,
133+
Dwarf_Handler errhand,
134+
Dwarf_Ptr errarg,
135+
Dwarf_Debug * ret_dbg,
136+
Dwarf_Error * error)
137+
{
138+
return dwarf_init_path_dl_a(path,
139+
true_path_out_buffer,true_path_bufferlen,
140+
groupnumber,universalnumber,
141+
errhand,errarg,ret_dbg,
142+
0,0,0,
143+
error);
144+
}
145+
128146
int dwarf_init_path(const char *path,
129147
char * true_path_out_buffer,
130148
unsigned true_path_bufferlen,
@@ -134,9 +152,11 @@ int dwarf_init_path(const char *path,
134152
Dwarf_Debug * ret_dbg,
135153
Dwarf_Error * error)
136154
{
137-
return dwarf_init_path_dl(path,
155+
unsigned int universalnumber = 0;
156+
return dwarf_init_path_dl_a(path,
138157
true_path_out_buffer,true_path_bufferlen,
139-
groupnumber,errhand,errarg,ret_dbg,
158+
groupnumber,universalnumber,
159+
errhand,errarg,ret_dbg,
140160
0,0,0,
141161
error);
142162
}
@@ -192,6 +212,30 @@ dwarf_init_path_dl(const char *path,
192212
unsigned int dl_path_count,
193213
unsigned char * path_source,
194214
Dwarf_Error * error)
215+
{
216+
unsigned int universalnumber = 0;
217+
int res = 0;
218+
219+
res = dwarf_init_path_dl_a(path,
220+
true_path_out_buffer, true_path_bufferlen,
221+
groupnumber,universalnumber,
222+
errhand,errarg,ret_dbg, dl_path_array,
223+
dl_path_count,path_source,error);
224+
return res;
225+
}
226+
int
227+
dwarf_init_path_dl_a(const char *path,
228+
char * true_path_out_buffer,
229+
unsigned true_path_bufferlen,
230+
unsigned groupnumber,
231+
unsigned universalnumber,
232+
Dwarf_Handler errhand,
233+
Dwarf_Ptr errarg,
234+
Dwarf_Debug * ret_dbg,
235+
char ** dl_path_array,
236+
unsigned int dl_path_count,
237+
unsigned char * path_source,
238+
Dwarf_Error * error)
195239
{
196240
unsigned ftype = 0;
197241
unsigned endian = 0;
@@ -302,9 +346,11 @@ dwarf_init_path_dl(const char *path,
302346
*ret_dbg = dbg;
303347
return res;
304348
}
349+
case DW_FTYPE_APPLEUNIVERSAL:
305350
case DW_FTYPE_MACH_O: {
306351
res = _dwarf_macho_setup(fd,
307352
file_path,
353+
universalnumber,
308354
ftype,endian,offsetsize,filesize,
309355
groupnumber,errhand,errarg,&dbg,error);
310356
if (res != DW_DLV_OK) {
@@ -355,6 +401,7 @@ dwarf_init_b(int fd,
355401
unsigned ftype = 0;
356402
unsigned endian = 0;
357403
unsigned offsetsize = 0;
404+
unsigned universalnumber = 0;
358405
Dwarf_Unsigned filesize = 0;
359406
int res = 0;
360407
int errcode = 0;
@@ -387,10 +434,12 @@ dwarf_init_b(int fd,
387434
set_global_paths_init(*ret_dbg,error);
388435
return res2;
389436
}
437+
case DW_FTYPE_APPLEUNIVERSAL:
390438
case DW_FTYPE_MACH_O: {
391439
int resm = 0;
392440

393441
resm = _dwarf_macho_setup(fd,"",
442+
universalnumber,
394443
ftype,endian,offsetsize,filesize,
395444
group_number,errhand,errarg,ret_dbg,error);
396445
if (resm != DW_DLV_OK) {

src/lib/libdwarf/dwarf_macho_loader.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,20 @@ extern "C" {
7676
#define TYP(n,l) char (n)[(l)]
7777
#endif /* TYP */
7878

79+
/* This is Apple internal naming for Universal Binaries
80+
and is not 'Inclusive Terminology" !! */
7981
#define FAT_MAGIC 0xcafebabe
80-
#define FAT_CIGAM 0xbebafeca /* NXSwapLong(FAT_MAGIC) */
82+
#define FAT_CIGAM 0xbebafeca
8183
#define FAT_MAGIC_64 0xcafebabf
82-
#define FAT_CIGAM_64 0xbfbafeca /* NXSwapLong(FAT_MAGIC_64) */
84+
#define FAT_CIGAM_64 0xbfbafeca
8385

8486
struct fat_header {
8587
TYP(magic,4); /* FAT_MAGIC or FAT_MAGIC_64 */
8688
TYP(nfat_arch,4); /* number of structs that follow */
8789
};
8890

8991
struct fat_arch {
90-
TYP(cputype,4); /* cpu specifier (int) */
92+
TYP(cputype ,4); /* cpu specifier (int) */
9193
TYP(cpusubtype,4); /* machine specifier (int) */
9294
TYP(offset,4); /* file offset to this object file */
9395
TYP(size,4); /* size of this object file */

0 commit comments

Comments
 (0)