Skip to content

Commit

Permalink
Handle ld error better in version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Nov 28, 2022
1 parent 9ea61c0 commit c611be9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pwnlib/asm.py
Expand Up @@ -276,17 +276,20 @@ def _linker():
'i386': ['-m', 'elf_i386'],
}.get(context.arch, [])

version = _run(ld + ["-v"])
if "GNU ld (GNU Binutils)" in version:
try:
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 ValueError:
pass
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

Expand Down

0 comments on commit c611be9

Please sign in to comment.