diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b8fa9c874..026494b264 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,6 +96,7 @@ The table below shows which release corresponds to each branch, and what date th - [#1981][1981] Fix `cyclic_find()` to make it work with large int values - [#2123][2123] Fix ROP without a writeable cache directory - [#2124][2124] Fix `tube.recvpred()` timout argument +- [#2141][2141] Fix `make_elf` on systems with GNU ld 2.39+ [1922]: https://github.com/Gallopsled/pwntools/pull/1922 [1828]: https://github.com/Gallopsled/pwntools/pull/1828 @@ -103,6 +104,7 @@ The table below shows which release corresponds to each branch, and what date th [1981]: https://github.com/Gallopsled/pwntools/pull/1981 [2123]: https://github.com/Gallopsled/pwntools/pull/2123 [2124]: https://github.com/Gallopsled/pwntools/pull/2124 +[2141]: https://github.com/Gallopsled/pwntools/pull/2141 ## 4.7.1 diff --git a/pwnlib/asm.py b/pwnlib/asm.py index 6e9b9f5fbe..5a1a47c41b 100644 --- a/pwnlib/asm.py +++ b/pwnlib/asm.py @@ -276,6 +276,21 @@ def _linker(): 'i386': ['-m', 'elf_i386'], }.get(context.arch, []) + try: + with context.local(log_level='critical'): + version = _run(ld + ["-v"]) + if "GNU ld (GNU Binutils)" in version: + number = version.split()[4] + major, minor, _ = [int(n) for n in number.split(".")] + # https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob_plain;f=ld/NEWS;hb=refs/heads/binutils-2_39-branch + # GNU ld 2.39+ will warn on RWX segments in an ELF + if (major == 2 and minor >= 39) or major > 2: + arguments.append("--no-warn-rwx-segments") + except Exception: + # If the output format is wrong or `ld -v` errors, just ignore it + # and (maybe) fail later + pass + return ld + bfd + [E] + arguments def _objcopy(): @@ -570,7 +585,8 @@ def make_elf(data, log.error("Cannot specify a VMA for a shared library.") if context.arch == 'thumb': - to_thumb = asm(shellcraft.arm.to_thumb(), arch='arm') + with context.local(arch='arm'): + to_thumb = asm(shellcraft.arm.to_thumb()) if not data.startswith(to_thumb): data = to_thumb + data