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 make_elf on systems with GNU ld 2.39+ #2141

Closed
wants to merge 1 commit into from

Conversation

clubby789
Copy link
Contributor

Fixes #2140

GNU ld 2.39 introduces a new warning which is always invoked by ELF.from_bytes and similar functions.

This PR detects affected versions of ld and adds an argument which ignores the warning.

@clubby789 clubby789 changed the base branch from dev to stable November 28, 2022 00:16
@clubby789
Copy link
Contributor Author

Pylint is failing because the existing error (E:585,19: Unexpected keyword argument 'arch' in function call (unexpected-keyword-arg)) has moved down by a few lines.

@clubby789 clubby789 force-pushed the fix-rwx-ld branch 2 times, most recently from d20ec6a to c611be9 Compare November 28, 2022 01:10
@clubby789
Copy link
Contributor Author

Sorry for the commit/CI spam - I'm not able to reproduce the particular failiure locally

@peace-maker
Copy link
Member

This appears to be a duplicate of #2098

@clubby789
Copy link
Contributor Author

Since the author of that PR hasnt responded, I've applied @Diff-fusion's suggestion of checking the return code of ld --no-warn-rwx-segments --help - it looks like many distros releases of ld have differently formatted version strings, and parsing them is probably going to be flaky.

@peace-maker
Copy link
Member

Nice, this looks more robust now. The same ld version introduced a warning about executable stacks too, so maybe adding --no-warn-execstack is in order like the other PR does?

@clubby789
Copy link
Contributor Author

I didn't include that one here, as the release notes specify that the warning will not be issued if an executable stack is specifically requested (-z execstack), which is used here. Detecting it introduces another point of failure/delay while that argument is checked.

We could add it unconditionally, but it's possible (while unlikely) some distros will compile with one flag but not the other.

# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob_plain;f=ld/NEWS;hb=refs/heads/binutils-2_39-branch
proc = subprocess.run(ld + ["--no-warn-rwx-segments", "--help"], capture_output=True)
if proc.returncode == 0:
arguments.append("--no-warn-rwx-segments")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please see the recommendation in #2140

@github-actions github-actions bot closed this in b8fad78 Dec 28, 2022
gogo2464 pushed a commit to gogo2464/pwntools that referenced this pull request Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ELF.from_bytes always throws exception (ld warning treated as error)
3 participants