Ld error 'missing .note.GNU-stack section'

when running $ dune build e.g. on project geohash I get:

$ dune build
/usr/local/bin/ld: warning: lib__Cgi.o: missing .note.GNU-stack section implies executable stack
/usr/local/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
/usr/local/bin/ld: warning: geohash.o: missing .note.GNU-stack section implies executable stack
/usr/local/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
/usr/local/bin/ld: warning: amd64.o: missing .note.GNU-stack section implies executable stack
/usr/local/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
/usr/local/bin/ld: warning: amd64.o: missing .note.GNU-stack section implies executable stack
/usr/local/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
/usr/local/bin/ld: warning: amd64.o: missing .note.GNU-stack section implies executable stack
/usr/local/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
/usr/local/bin/ld: warning: amd64.o: missing .note.GNU-stack section implies executable stack
/usr/local/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker

It’s on a newly installed FreeBSD 13.2 on a Thinkpad (x250).

$ ld --version
LLD 14.0.5 (FreeBSD llvmorg-14.0.5-0-gc12386ae247c-1400004) (compatible with GNU linkers)
$ dune --version
3.8.2
$ opam switch
#  switch   compiler                    description
→  4.11.2   ocaml-base-compiler.4.11.2  4.11.2

How can I get rid of this annoyance?

There is something strange going on: the lld linker ignores note.GNU-stack as a policy, and the warning that you see is a BFD warning.

Anyway, you should be able to silence those warnings by adding -z noexecflags -z noexecstack to the linker flags.

1 Like

@octachron thanks for helping me, sadly I don’t know how to do that. Stanza Reference — Dune documentation was not helpful.

When I do this unsuccessfully trying to add linker flags. · e7a0274735 - geohash - Codeberg.org there is no effect. I tried a dozend variations and spent almost an hour.

Where do I have to put what?

Using the correct name (sorry for the mistake) with

(flags (:standard -cclib "-z noexecstack"))

should work. Nevertheless, it is probably a good idea ti check that the option is recognized with the linker by building in verbose mode:

dune build --verbose
1 Like

Thanks @octachron, never would have figured that out alone.

I had to combine flagswith the previously existing link_flags and finally succeeded at silence the linker warning '.. missing .note.GNU-stack section ..' · 0a32c16b1b - geohash - Codeberg.org.

Using link_flags alone didn’t work. And had to add flags to test/dune, naturally.