jart / cosmopolitan

build-once run-anywhere c library
ISC License
18.26k stars 625 forks source link

Linker warning on MacOS: `missing .note.GNU-stack section implies executable stack` #590

Open legendre6891 opened 2 years ago

legendre6891 commented 2 years ago

Hi! Really impressive project 👍

I followed the README instructions on MacOS and successfully compiled hello.com. One thing while following the instructions are the following warnings: wondering if this is expected? Thanks!

$ x86_64-elf-gcc -g -Os -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \
  -fno-omit-frame-pointer -pg -mnop-mcount -mno-tls-direct-seg-refs \
  -o hello.com.dbg hello.c -fuse-ld=bfd -Wl,-T,ape.lds -Wl,--gc-sections \
  -include cosmopolitan.h crt.o ape-no-modify-self.o cosmopolitan.a

/opt/homebrew/opt/x86_64-elf-binutils/bin/x86_64-elf-ld.bfd: warning: /var/folders/yf/3nc093xs49b_l61tzdwkwzww0000gn/T//ccqCvGEs.o: missing .note.GNU-stack section implies executable stack
/opt/homebrew/opt/x86_64-elf-binutils/bin/x86_64-elf-ld.bfd: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
/opt/homebrew/opt/x86_64-elf-binutils/bin/x86_64-elf-ld.bfd: hello.com.dbg: warning: allocated section `.tdata' not in segment

Information about my system:

jart commented 2 years ago

The .tdata warning was fixed yesterday in https://github.com/jart/cosmopolitan/commit/3c00d8c29c9fa903a486377d6317a2374f49c457 As for the executable stack warning, it's harmless since we don't need it. Contributions are welcome if someone wants to add the appropriate declaration to ape.S that'll make that go away for the version of GCC you're using.

legendre6891 commented 2 years ago

Thank you Justine: I could look into it but my level of expertise is quite limited; for my future reference, the version of gcc is

x86_64-elf-gcc (GCC) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
tkchia commented 2 years ago

Hello @jart, hello @legendre6891,

I am kind of surprised that macOS Homebrew's ELF linker (?) is looking for a .note.GNU-stack section, even though the ape/ape.lds linker script already explicitly defines a PT_GNU_STACK segment with explicit segment flags.

And apparently the problem is not so easy to fix either. If the Gentoo Linux wiki is any guide, it seems that all the .o modules involved in the final program linking may need to be fitted with .note.GNU-stack sections.

Thank you!