Skip to content

Conversation

@symphorien
Copy link

On GNU/Linux, when linking an executable comprising psm in a static library created by cargo because Cargo.toml contains crate-type = ["staticlib"], the linker outputs the following warning:

/nix/store/dc9vaz50jg7mibk9xvqw5dqv89cxzla3-binutils-2.44/bin/ld: warning: 4f9a91766097c4c5-x86_64.o: missing .note.GNU-stack section implies executable stack
/nix/store/dc9vaz50jg7mibk9xvqw5dqv89cxzla3-binutils-2.44/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker

(where 4f9a91766097c4c5-x86_64.o is the object corresponding to psm/src/arch/x86_64.s)

Add the note requested by the linker.

For some reason, executables linked directly by rustc do not seem affected. I only observed this with a c++ project linking a rust static library comprising psm (lnav).

Note that I'm quite out of my depth here, and that I have only tested on x86_64-linux-gnu. I expect that a note will not be problematic with non-gnu toolchains, which should ignore it.

@symphorien symphorien force-pushed the master branch 5 times, most recently from 36ac295 to 5abb754 Compare January 4, 2026 20:58
@@ -0,0 +1,3 @@
#if defined(__linux__) && defined(__ELF__)
Copy link
Member

Choose a reason for hiding this comment

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

Probably should be checking for __gnu_linux__ or __GNUC__ (which despite having "C" in its name) is defined when compiling assembly and is going to be specific for gnu targets where this matters.

Copy link
Member

Choose a reason for hiding this comment

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

Additionally, lets rename the file to be more self-descriptive (e.g. gnu_stack_note.s)

Copy link
Author

Choose a reason for hiding this comment

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

gentoo wiki recommends it this way. https://wiki.gentoo.org/wiki/Hardened/GNU_stack_quickstart#Patching

I suspect it covers the case where the assembler is not gnu but the linker is (as this note is directed to the linker, as far as I understand)

Copy link
Author

Choose a reason for hiding this comment

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

Additionally, lets rename the file to be more self-descriptive (e.g. gnu_stack_note.s)

Done

Copy link
Member

Choose a reason for hiding this comment

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

Hm, having done some more research, I think this check could drop the linux check altogether and just condition on just the

defined(__ELF__)

https://github.com/llvm/llvm-project/blob/66df6cceea001a2082bc78678305a86b9bb29ecb/llvm/lib/MC/MCAsmInfoELF.cpp#L30-L37 does not emit this section on solaris, but psm does not need to worry too much about creating that one superfluous mini-section on targets that might not use it.

On GNU/Linux, when linking an executable comprising a static library
created by cargo because Cargo.toml contains crate-type = ["staticlib"]
the linker outputs the following warning:

```
/nix/store/dc9vaz50jg7mibk9xvqw5dqv89cxzla3-binutils-2.44/bin/ld: warning: 4f9a91766097c4c5-x86_64.o: missing .note.GNU-stack section implies executable stack
/nix/store/dc9vaz50jg7mibk9xvqw5dqv89cxzla3-binutils-2.44/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
```

(where 4f9a91766097c4c5-x86_64.o is the object corresponding to
psm/src/arch/x86_64.s)

Add the note requested by the linker.

For some reason, executables linked directly by rustc do not seem
affected. I only observed this with a c++ project linking a rust static
library comprising psm (lnav).
@symphorien
Copy link
Author

can you restart the job that failed due to a timeout? It seems the button to do it is privileged.

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.

2 participants