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

[RFC] Use lief library and stop depending on binutils #5996

Open
wants to merge 1 commit into
base: develop
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
pip install --progress-bar=off -U -r tests/requirements-tools.txt -r tests/requirements-libraries.txt
# Compile bootloader
cd bootloader
python waf all
python waf all CFLAGS="-fcf-protection=none"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does control-flow transfer instrumentation interfere with executable modification made via lief?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cd ..
# Install PyInstaller.
Expand Down
20 changes: 9 additions & 11 deletions PyInstaller/building/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,18 +682,16 @@ def assemble(self):
logger.info("Copying archive to %s", self.pkgname)
self._copyfile(self.pkg.name, self.pkgname)
elif is_linux:
self._copyfile(exe, self.name)
import lief
logger.info("Appending archive to ELF section in EXE %s", self.name)
retcode, stdout, stderr = exec_command_all(
'objcopy', '--add-section', 'pydata=%s' % self.pkg.name,
self.name)
logger.debug("objcopy returned %i", retcode)
if stdout:
logger.debug(stdout)
if stderr:
logger.debug(stderr)
if retcode != 0:
raise SystemError("objcopy Failure: %s" % stderr)
elf_target = lief.parse(exe)
elf_section = lief.ELF.Section()
elf_section.name = "pydata"
elf_section.type = lief.ELF.SECTION_TYPES.PROGBITS
with open(self.pkg.name, "rb") as elf_section_data:
elf_section.content = list(elf_section_data.read())
elf_section = elf_target.add(elf_section, True)
elf_target.write(self.name)
elif is_darwin:
import PyInstaller.utils.osx as osxutils

Expand Down
15 changes: 6 additions & 9 deletions PyInstaller/depend/bindepend.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,16 +844,13 @@ def _get_so_name(filename):
"""
Return the soname of a library.

Soname is usefull whene there are multiple symplinks to one library.
Soname is useful when there are multiple symlinks to one library.
"""
# TODO verify that objdump works on other unixes and not Linux only.
cmd = ["objdump", "-p", filename]
pattern = r'\s+SONAME\s+([^\s]+)'
if compat.is_solar:
cmd = ["elfdump", "-d", filename]
pattern = r'\s+SONAME\s+[^\s]+\s+([^\s]+)'
m = re.search(pattern, compat.exec_command(*cmd))
return m.group(1)

import lief
elf_target = lief.parse(filename)
elf_target_soname = elf_target[lief.ELF.DYNAMIC_TAGS.SONAME].name
return elf_target_soname


def get_python_library_path():
Expand Down
6 changes: 0 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ Requirements and Tested Platforms
- ldd: Console application to print the shared libraries required
by each program or shared library. This typically can be found in
the distribution-package `glibc` or `libc-bin`.
- objdump: Console application to display information from
object files. This typically can be found in the
distribution-package `binutils`.
- objcopy: Console application to copy and translate object files.
This typically can be found in the distribution-package `binutils`,
too.

- Mac OS X (64bit):

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ install_requires =
pefile >= 2017.8.1 ; sys_platform == 'win32'
pywin32-ctypes >= 0.2.0 ; sys_platform == 'win32'
macholib >= 1.8 ; sys_platform == 'darwin'
lief >= 0.11.5 ; sys_platform == 'linux'
pyinstaller-hooks-contrib >= 2020.6
importlib-metadata ; python_version < '3.8'

Expand Down