Skip to content

Instantly share code, notes, and snippets.

@depressed-pho
Last active January 15, 2023 15:15
Show Gist options
  • Save depressed-pho/2d379beb39759d810c93d19dda42eede to your computer and use it in GitHub Desktop.
Save depressed-pho/2d379beb39759d810c93d19dda42eede to your computer and use it in GitHub Desktop.
Binutils 2.39 on NetBSD-current
.text
.globl main
.type main, @function
main:
ret
gnu-stack: merged.o
cc -o $@ merged.o
@{ readelf -e $@ | grep -A1 GNU_STACK; } || echo " $@ has no .note.GNU-stack"
merged.o: main.o sub.o sub2.o
ld -r -o $@ main.o sub.o sub2.o
@{ readelf -e $@ | grep -A1 GNU-stack; } || echo " $@ has no .note.GNU-stack"
.s.o:
cc -o $@ -c $<
@{ readelf -e $@ | grep -A1 GNU-stack; } || echo " $@ has no .note.GNU-stack"
.c.o:
cc -o $@ -c $<
@{ readelf -e $@ | grep -A1 GNU-stack; } || echo " $@ has no .note.GNU-stack"
.PHONY: clean
clean:
rm -f *.o gnu-stack
% make
cc -o main.o -c main.s
main.o has no .note.GNU-stack
cc -o sub.o -c sub.s
[ 4] .note.GNU-stack PROGBITS 0000000000000000 00000041
0000000000000000 0000000000000000 0 0 1
cc -o sub2.o -c sub2.c
sub2.o has no .note.GNU-stack
ld -r -o merged.o main.o sub.o sub2.o
ld: warning: sub2.o: missing .note.GNU-stack section implies executable stack
ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
[ 7] .note.GNU-stack PROGBITS 0000000000000000 000000a4
0000000000000000 0000000000000000 X 0 0 1
cc -o gnu-stack merged.o
ld: warning: merged.o: requires executable stack (because the .note.GNU-stack section is executable)
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RWE 0x10
.text
.globl sub
.type sub, @function
sub:
ret
.section .note.GNU-stack,"",@progbits
void sub2() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment