Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macOS and binutils>=2.29 support #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,32 @@ Because it seems that **pybfd** is no longer maintained, I decided to create my

## Requirements

### Linux

- The **binutils-dev** package must be installed first.

### macOS

The default brew install doesn't include the required library `libiberty`, because of this you need to modify the brew formula to build and install `libiberty`. To do this run:

```
$ brew edit binutils
```

Scroll down the `def install` section and add `--enable-install-libiberty` to the `configure` arguments so that it looks like the following:

```
"--disable-nls",
"--enable-install-libiberty"
system "make"
```

Now run the following command to force brew to build locally instead of from a bottle:

```
$ brew install --build-from-source binutils
```

## Install

Method 1: Via Python Package Index (PyPI).
Expand Down
27 changes: 25 additions & 2 deletions pybfd3/gen_supported_disasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
("bfd_arch_avr", "print_insn_avr", "print_insn_avr", "Atmel AVR microcontrollers."),
("bfd_arch_bfin", "print_insn_bfin", "print_insn_bfin", "ADI Blackfin"),
("bfd_arch_cr16", "print_insn_cr16", "print_insn_cr16", "National Semiconductor CompactRISC (ie CR16)."),
("bfd_arch_cr16c", "print_insn_cr16", "print_insn_cr16", "National Semiconductor CompactRISC."),
# ("bfd_arch_cr16c", "print_insn_cr16", "print_insn_cr16", "National Semiconductor CompactRISC."),
("bfd_arch_crx", "print_insn_crx", "print_insn_crx", "National Semiconductor CRX."),
("bfd_arch_rx", "print_insn_rx", "print_insn_rx", "Renesas RX."),
("bfd_arch_s390", "print_insn_s390", "print_insn_s390", "IBM s390"),
Expand Down Expand Up @@ -106,6 +106,8 @@
# bfd_arch_cris - Axis CRIS
]

bfd2_29_extern = "int %s(bfd_vma, disassemble_info *);";

supported_archs_header = """
#ifndef __SUPPORTED_DISASM_H_
#define __SUPPORTED_DISASM_H_
Expand All @@ -122,6 +124,9 @@
disassembler_ftype bfd_print_insn_endian_big;
} supported_disasm, *p_supported_disasm;

#ifdef PYBFD3_BFD_GE_2_29
%s
#endif

supported_disasm p_supported_disasm_list[]= {
%s
Expand All @@ -146,6 +151,10 @@

#define py_const_def(c,v) fprintf(fd, #c " = %%d\n", v);

#ifdef PYBFD3_BFD_GE_2_29
%s
#endif

//
// Name : write_architectures_constants
//
Expand Down Expand Up @@ -221,27 +230,41 @@ def generate_supported_disassembler_header(supported_archs):

"""
arch_entries = []
arch_externs = []

for arch, little, big, comment in supported_archs:
arch_entries.append( header_arch_entry % (arch, little, big) )
arch_externs.append( bfd2_29_extern % little )

if little != big:
arch_externs.append( bfd2_29_extern % big )

return supported_archs_header % ( ",\n".join(arch_entries) )
return supported_archs_header % (
"\n".join(arch_externs),
",\n".join(arch_entries))

def generate_supported_architectures_source(supported_archs, supported_machines):
"""Extract export symbols using binutils's nm utility from Binutils and
generate a current header for PyBFD3.

"""
arch_entries = []
arch_externs = []
mach_entries = []

# int %s(bfd_vma, disassemble_info *);
for arch, little, big, comment in supported_archs:
arch_entries.append( pybfd3_arch_entry % (arch[4 : ].upper(), arch) )
arch_externs.append( bfd2_29_extern % little )

if little != big:
arch_externs.append( bfd2_29_extern % big )

for mach, value in supported_machines:
mach_entries.append( pybfd3_mach_entry % (mach[4 : ].upper(), value) )

return gen_bfd_archs_code % (
"\n".join(arch_externs),
"\n".join(arch_entries),
"\n".join(mach_entries))

Expand Down
13 changes: 9 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ class CustomBuildExtension( build_ext ):
"darwin": {
"libs": [
"/opt/local/lib", # macports
"/usr/local/lib", # homebrew
"/usr/local/lib", # homebrew 1
"/usr/local/opt/binutils/lib", # homebrew 2
],
"includes": [
"/opt/local/include", # macports
"/usr/local/include", # homebrew
"/usr/local/include", # homebrew 1
"/usr/local/opt/binutils/include", # homebrew 2
],
"possible-lib-ext": [
".a", # homebrew
Expand Down Expand Up @@ -378,8 +380,9 @@ def build_extensions(self):
if self.with_static_binutils or sys.platform == "darwin": # in OSX we always needs a static lib-iverty.

lib_liberty_partialpath = [lib_path for lib_path in libraries_paths]
if sys.platform == "darwin": # in osx the lib-iberty is prefixe by "machine" ppc/i386/x86_64
lib_liberty_partialpath.append( self._darwin_current_arch() )
# NOTE: At least on Catalina, this is no longer the case
# if sys.platform == "darwin": # in osx the lib-iberty is prefixe by "machine" ppc/i386/x86_64
# lib_liberty_partialpath.append( self._darwin_current_arch() )
lib_liberty_partialpath.append( "libiberty.a" )

lib_liberty_fullpath = os.path.join(*lib_liberty_partialpath ) # merge the prefix and the path
Expand Down Expand Up @@ -412,6 +415,8 @@ def build_extensions(self):
os.environ["ARCHFLAGS"] = "-arch %s" % self._darwin_current_arch()
# In OSX we've to link against libintl.
ext_libs.append("intl")
# In OSX we also must link against libz
ext_libs.append("z")

# TODO: we have to improve the detection of gettext/libintl in OSX.. this is a quick fix.
dirs = [
Expand Down