Don't include libbfd.h outside of bfd, part 3

Fix od-macho.c to use a leb128 function from binutils/dwarf.c rather
than one from bfd/libbfd.c.

binutils/
	* elfcomm.h (HOST_WIDEST_INT): Move to..
	* sysdep.h: ..here.
	* od-macho.c: Don't include libbfd.h.  Do include dwarf.h
	(dump_dyld_info_rebase): Use read_leb128 rather than
	read_unsigned_leb128.
	(dump_dyld_info_bind, dump_dyld_info_export_1): Likewise.
	(dump_segment_split_info): Likewise.
	(dump_dyld_info): Rename vars to avoid shadowing dwarf.h enums.
	(dump_load_command): Likewise.
This commit is contained in:
Alan Modra 2016-07-16 13:28:30 +09:30
parent 00dad9a491
commit 16412c3bc4
4 changed files with 60 additions and 47 deletions

View file

@ -1,3 +1,15 @@
2016-07-16 Alan Modra <amodra@gmail.com>
* elfcomm.h (HOST_WIDEST_INT): Move to..
* sysdep.h: ..here.
* od-macho.c: Don't include libbfd.h. Do include dwarf.h
(dump_dyld_info_rebase): Use read_leb128 rather than
read_unsigned_leb128.
(dump_dyld_info_bind, dump_dyld_info_export_1): Likewise.
(dump_segment_split_info): Likewise.
(dump_dyld_info): Rename vars to avoid shadowing dwarf.h enums.
(dump_load_command): Likewise.
2016-07-16 Alan Modra <amodra@gmail.com> 2016-07-16 Alan Modra <amodra@gmail.com>
* ar.c: Don't include libbfd.h. * ar.c: Don't include libbfd.h.

View file

@ -29,13 +29,6 @@
void error (const char *, ...) ATTRIBUTE_PRINTF_1; void error (const char *, ...) ATTRIBUTE_PRINTF_1;
void warn (const char *, ...) ATTRIBUTE_PRINTF_1; void warn (const char *, ...) ATTRIBUTE_PRINTF_1;
#if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
/* We can't use any bfd types here since readelf may define BFD64 and
objdump may not. */
#define HOST_WIDEST_INT long long
#else
#define HOST_WIDEST_INT long
#endif
typedef unsigned HOST_WIDEST_INT elf_vma; typedef unsigned HOST_WIDEST_INT elf_vma;
extern void (*byte_put) (unsigned char *, elf_vma, int); extern void (*byte_put) (unsigned char *, elf_vma, int);

View file

@ -26,8 +26,8 @@
#include "bfd.h" #include "bfd.h"
#include "objdump.h" #include "objdump.h"
#include "bucomm.h" #include "bucomm.h"
#include "dwarf.h"
#include "bfdlink.h" #include "bfdlink.h"
#include "libbfd.h"
#include "mach-o.h" #include "mach-o.h"
#include "mach-o/external.h" #include "mach-o/external.h"
#include "mach-o/codesign.h" #include "mach-o/codesign.h"
@ -688,13 +688,13 @@ dump_dyld_info_rebase (bfd *abfd, unsigned char *buf, unsigned int len,
bfd_mach_o_get_name (bfd_mach_o_dyld_rebase_type_name, imm)); bfd_mach_o_get_name (bfd_mach_o_dyld_rebase_type_name, imm));
break; break;
case BFD_MACH_O_REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: case BFD_MACH_O_REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
leb = read_unsigned_leb128 (abfd, buf + i, &leblen); leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("set segment: %u and offset: 0x%08x\n", printf ("set segment: %u and offset: 0x%08x\n",
imm, (unsigned) leb); imm, (unsigned) leb);
i += leblen; i += leblen;
break; break;
case BFD_MACH_O_REBASE_OPCODE_ADD_ADDR_ULEB: case BFD_MACH_O_REBASE_OPCODE_ADD_ADDR_ULEB:
leb = read_unsigned_leb128 (abfd, buf + i, &leblen); leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("add addr uleb: 0x%08x\n", (unsigned) leb); printf ("add addr uleb: 0x%08x\n", (unsigned) leb);
i += leblen; i += leblen;
break; break;
@ -705,20 +705,20 @@ dump_dyld_info_rebase (bfd *abfd, unsigned char *buf, unsigned int len,
printf ("rebase imm times: %u\n", imm); printf ("rebase imm times: %u\n", imm);
break; break;
case BFD_MACH_O_REBASE_OPCODE_DO_REBASE_ULEB_TIMES: case BFD_MACH_O_REBASE_OPCODE_DO_REBASE_ULEB_TIMES:
leb = read_unsigned_leb128 (abfd, buf + i, &leblen); leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("rebase uleb times: %u\n", (unsigned) leb); printf ("rebase uleb times: %u\n", (unsigned) leb);
i += leblen; i += leblen;
break; break;
case BFD_MACH_O_REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB: case BFD_MACH_O_REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB:
leb = read_unsigned_leb128 (abfd, buf + i, &leblen); leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("rebase add addr uleb: %u\n", (unsigned) leb); printf ("rebase add addr uleb: %u\n", (unsigned) leb);
i += leblen; i += leblen;
break; break;
case BFD_MACH_O_REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB: case BFD_MACH_O_REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB:
leb = read_unsigned_leb128 (abfd, buf + i, &leblen); leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("rebase uleb times (%u)", (unsigned) leb); printf ("rebase uleb times (%u)", (unsigned) leb);
i += leblen; i += leblen;
leb = read_unsigned_leb128 (abfd, buf + i, &leblen); leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf (" skipping uleb (%u)\n", (unsigned) leb); printf (" skipping uleb (%u)\n", (unsigned) leb);
i += leblen; i += leblen;
break; break;
@ -755,7 +755,7 @@ dump_dyld_info_bind (bfd *abfd, unsigned char *buf, unsigned int len,
printf ("set dylib ordinal imm: %u\n", imm); printf ("set dylib ordinal imm: %u\n", imm);
break; break;
case BFD_MACH_O_BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB: case BFD_MACH_O_BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB:
leb = read_unsigned_leb128 (abfd, buf + i, &leblen); leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("set dylib ordinal uleb: %u\n", imm); printf ("set dylib ordinal uleb: %u\n", imm);
i += leblen; i += leblen;
break; break;
@ -778,19 +778,19 @@ dump_dyld_info_bind (bfd *abfd, unsigned char *buf, unsigned int len,
case BFD_MACH_O_BIND_OPCODE_SET_ADDEND_SLEB: case BFD_MACH_O_BIND_OPCODE_SET_ADDEND_SLEB:
{ {
bfd_signed_vma svma; bfd_signed_vma svma;
svma = read_unsigned_leb128 (abfd, buf + i, &leblen); svma = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("set addend sleb: 0x%08x\n", (unsigned) svma); printf ("set addend sleb: 0x%08x\n", (unsigned) svma);
i += leblen; i += leblen;
} }
break; break;
case BFD_MACH_O_BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: case BFD_MACH_O_BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB:
leb = read_unsigned_leb128 (abfd, buf + i, &leblen); leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("set segment: %u and offset: 0x%08x\n", printf ("set segment: %u and offset: 0x%08x\n",
imm, (unsigned) leb); imm, (unsigned) leb);
i += leblen; i += leblen;
break; break;
case BFD_MACH_O_BIND_OPCODE_ADD_ADDR_ULEB: case BFD_MACH_O_BIND_OPCODE_ADD_ADDR_ULEB:
leb = read_unsigned_leb128 (abfd, buf + i, &leblen); leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("add addr uleb: 0x%08x\n", (unsigned) leb); printf ("add addr uleb: 0x%08x\n", (unsigned) leb);
i += leblen; i += leblen;
break; break;
@ -798,7 +798,7 @@ dump_dyld_info_bind (bfd *abfd, unsigned char *buf, unsigned int len,
printf ("do bind\n"); printf ("do bind\n");
break; break;
case BFD_MACH_O_BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB: case BFD_MACH_O_BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB:
leb = read_unsigned_leb128 (abfd, buf + i, &leblen); leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("do bind add addr uleb: 0x%08x\n", (unsigned) leb); printf ("do bind add addr uleb: 0x%08x\n", (unsigned) leb);
i += leblen; i += leblen;
break; break;
@ -806,10 +806,10 @@ dump_dyld_info_bind (bfd *abfd, unsigned char *buf, unsigned int len,
printf ("do bind add addr imm scaled: %u\n", imm * ptrsize); printf ("do bind add addr imm scaled: %u\n", imm * ptrsize);
break; break;
case BFD_MACH_O_BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB: case BFD_MACH_O_BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB:
leb = read_unsigned_leb128 (abfd, buf + i, &leblen); leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf ("do bind uleb times (%u)", (unsigned) leb); printf ("do bind uleb times (%u)", (unsigned) leb);
i += leblen; i += leblen;
leb = read_unsigned_leb128 (abfd, buf + i, &leblen); leb = read_leb128 (buf + i, &leblen, 0, buf + len);
printf (" skipping uleb (%u)\n", (unsigned) leb); printf (" skipping uleb (%u)\n", (unsigned) leb);
i += leblen; i += leblen;
break; break;
@ -837,7 +837,7 @@ dump_dyld_info_export_1 (bfd *abfd, unsigned char *buf, unsigned int len,
unsigned int child_count; unsigned int child_count;
unsigned int i; unsigned int i;
size = read_unsigned_leb128 (abfd, buf + off, &leblen); size = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen; off += leblen;
if (size != 0) if (size != 0)
@ -845,7 +845,7 @@ dump_dyld_info_export_1 (bfd *abfd, unsigned char *buf, unsigned int len,
bfd_vma flags; bfd_vma flags;
struct export_info_data *d; struct export_info_data *d;
flags = read_unsigned_leb128 (abfd, buf + off, &leblen); flags = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen; off += leblen;
fputs (" ", stdout); fputs (" ", stdout);
@ -868,7 +868,7 @@ dump_dyld_info_export_1 (bfd *abfd, unsigned char *buf, unsigned int len,
{ {
bfd_vma lib; bfd_vma lib;
lib = read_unsigned_leb128 (abfd, buf + off, &leblen); lib = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen; off += leblen;
fputs (" [reexport] ", stdout); fputs (" [reexport] ", stdout);
@ -890,12 +890,12 @@ dump_dyld_info_export_1 (bfd *abfd, unsigned char *buf, unsigned int len,
bfd_vma offset; bfd_vma offset;
bfd_vma resolv = 0; bfd_vma resolv = 0;
offset = read_unsigned_leb128 (abfd, buf + off, &leblen); offset = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen; off += leblen;
if (flags & BFD_MACH_O_EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER) if (flags & BFD_MACH_O_EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER)
{ {
resolv = read_unsigned_leb128 (abfd, buf + off, &leblen); resolv = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen; off += leblen;
} }
@ -908,7 +908,7 @@ dump_dyld_info_export_1 (bfd *abfd, unsigned char *buf, unsigned int len,
} }
} }
child_count = read_unsigned_leb128 (abfd, buf + off, &leblen); child_count = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen; off += leblen;
for (i = 0; i < child_count; i++) for (i = 0; i < child_count; i++)
@ -922,7 +922,7 @@ dump_dyld_info_export_1 (bfd *abfd, unsigned char *buf, unsigned int len,
off += strlen ((const char *)buf + off) + 1; off += strlen ((const char *)buf + off) + 1;
sub_off = read_unsigned_leb128 (abfd, buf + off, &leblen); sub_off = read_leb128 (buf + off, &leblen, 0, buf + len);
off += leblen; off += leblen;
dump_dyld_info_export_1 (abfd, buf, len, sub_off, &sub_data, base); dump_dyld_info_export_1 (abfd, buf, len, sub_off, &sub_data, base);
@ -946,49 +946,49 @@ static void
dump_dyld_info (bfd *abfd, bfd_mach_o_load_command *cmd, dump_dyld_info (bfd *abfd, bfd_mach_o_load_command *cmd,
bfd_boolean verbose) bfd_boolean verbose)
{ {
bfd_mach_o_dyld_info_command *info = &cmd->command.dyld_info; bfd_mach_o_dyld_info_command *dinfo = &cmd->command.dyld_info;
printf (" rebase: off: 0x%08x size: %-8u (endoff: 0x%08x)\n", printf (" rebase: off: 0x%08x size: %-8u (endoff: 0x%08x)\n",
info->rebase_off, info->rebase_size, dinfo->rebase_off, dinfo->rebase_size,
info->rebase_off + info->rebase_size); dinfo->rebase_off + dinfo->rebase_size);
printf (" bind: off: 0x%08x size: %-8u (endoff: 0x%08x)\n", printf (" bind: off: 0x%08x size: %-8u (endoff: 0x%08x)\n",
info->bind_off, info->bind_size, dinfo->bind_off, dinfo->bind_size,
info->bind_off + info->bind_size); dinfo->bind_off + dinfo->bind_size);
printf (" weak bind: off: 0x%08x size: %-8u (endoff: 0x%08x)\n", printf (" weak bind: off: 0x%08x size: %-8u (endoff: 0x%08x)\n",
info->weak_bind_off, info->weak_bind_size, dinfo->weak_bind_off, dinfo->weak_bind_size,
info->weak_bind_off + info->weak_bind_size); dinfo->weak_bind_off + dinfo->weak_bind_size);
printf (" lazy bind: off: 0x%08x size: %-8u (endoff: 0x%08x)\n", printf (" lazy bind: off: 0x%08x size: %-8u (endoff: 0x%08x)\n",
info->lazy_bind_off, info->lazy_bind_size, dinfo->lazy_bind_off, dinfo->lazy_bind_size,
info->lazy_bind_off + info->lazy_bind_size); dinfo->lazy_bind_off + dinfo->lazy_bind_size);
printf (" export: off: 0x%08x size: %-8u (endoff: 0x%08x)\n", printf (" export: off: 0x%08x size: %-8u (endoff: 0x%08x)\n",
info->export_off, info->export_size, dinfo->export_off, dinfo->export_size,
info->export_off + info->export_size); dinfo->export_off + dinfo->export_size);
if (!verbose) if (!verbose)
return; return;
printf (" rebase:\n"); printf (" rebase:\n");
if (!load_and_dump (abfd, info->rebase_off, info->rebase_size, if (!load_and_dump (abfd, dinfo->rebase_off, dinfo->rebase_size,
dump_dyld_info_rebase)) dump_dyld_info_rebase))
non_fatal (_("cannot read rebase dyld info")); non_fatal (_("cannot read rebase dyld info"));
printf (" bind:\n"); printf (" bind:\n");
if (!load_and_dump (abfd, info->bind_off, info->bind_size, if (!load_and_dump (abfd, dinfo->bind_off, dinfo->bind_size,
dump_dyld_info_bind)) dump_dyld_info_bind))
non_fatal (_("cannot read bind dyld info")); non_fatal (_("cannot read bind dyld info"));
printf (" weak bind:\n"); printf (" weak bind:\n");
if (!load_and_dump (abfd, info->weak_bind_off, info->weak_bind_size, if (!load_and_dump (abfd, dinfo->weak_bind_off, dinfo->weak_bind_size,
dump_dyld_info_bind)) dump_dyld_info_bind))
non_fatal (_("cannot read weak bind dyld info")); non_fatal (_("cannot read weak bind dyld info"));
printf (" lazy bind:\n"); printf (" lazy bind:\n");
if (!load_and_dump (abfd, info->lazy_bind_off, info->lazy_bind_size, if (!load_and_dump (abfd, dinfo->lazy_bind_off, dinfo->lazy_bind_size,
dump_dyld_info_bind)) dump_dyld_info_bind))
non_fatal (_("cannot read lazy bind dyld info")); non_fatal (_("cannot read lazy bind dyld info"));
printf (" exported symbols:\n"); printf (" exported symbols:\n");
if (!load_and_dump (abfd, info->export_off, info->export_size, if (!load_and_dump (abfd, dinfo->export_off, dinfo->export_size,
dump_dyld_info_export)) dump_dyld_info_export))
non_fatal (_("cannot read export symbols dyld info")); non_fatal (_("cannot read export symbols dyld info"));
} }
@ -1287,7 +1287,7 @@ dump_segment_split_info (bfd *abfd, bfd_mach_o_linkedit_command *cmd)
} }
for (p = buf + 1; *p != 0; p += len) for (p = buf + 1; *p != 0; p += len)
{ {
addr += read_unsigned_leb128 (abfd, p, &len); addr += read_leb128 (p, &len, 0, buf + cmd->datasize);
fputs (" ", stdout); fputs (" ", stdout);
bfd_printf_vma (abfd, addr); bfd_printf_vma (abfd, addr);
putchar ('\n'); putchar ('\n');
@ -1556,8 +1556,8 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
case BFD_MACH_O_LC_SUB_CLIENT: case BFD_MACH_O_LC_SUB_CLIENT:
case BFD_MACH_O_LC_RPATH: case BFD_MACH_O_LC_RPATH:
{ {
bfd_mach_o_str_command *str = &cmd->command.str; bfd_mach_o_str_command *strc = &cmd->command.str;
printf (" %s\n", str->str); printf (" %s\n", strc->str);
break; break;
} }
case BFD_MACH_O_LC_THREAD: case BFD_MACH_O_LC_THREAD:

View file

@ -187,4 +187,12 @@ size_t strnlen (const char *, size_t);
# endif # endif
#endif #endif
#if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
/* We can't use any bfd types here since readelf may define BFD64 and
objdump may not. */
#define HOST_WIDEST_INT long long
#else
#define HOST_WIDEST_INT long
#endif
#endif /* _BIN_SYSDEP_H */ #endif /* _BIN_SYSDEP_H */