Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fix "/usr/bin/ld: warning: trap.o: missing .note.GNU-stack section implies executable stack"?

I compiled the same project on ubuntu20.04 in wsl and my main used OS archLinux respectively. On wsl, everything went normal, while on archlinux the error message as follows would show:

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

It seems like an error caused by the linker ld, the version message of it on my Linux OS is:

GNU ld (GNU Binutils) 2.39
Copyright (C) 2022 Free Software Foundation, Inc.

And my wsl has:

GNU ld (GNU Binutils for Ubuntu) 2.34
Copyright (C) 2020 Free Software Foundation, Inc.

On arch, gcc's version is 12.1.1, while on wsl it is gcc 9.3.0

Was it caused by the difference between the old and new versions? How can I fix it?

like image 240
wuliJerry Avatar asked Jan 21 '26 16:01

wuliJerry


2 Answers

Call with ld option -z noexecstack.

Credit to https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ffcf9c5700e49c0aee42dcba9a12ba21338e8136.

like image 103
Kai Avatar answered Jan 23 '26 07:01

Kai


This is a new warning message introduced by GNU bin-utils version 2.39.

Here is quotation from the release message:

The ELF linker will now generate a warning message if the stack is made executable. Similarly it will warn if the output binary contains a segment with all three of the read, write and execute permission bits set. These warnings are intended to help developers identify programs which might be vulnerable to attack via these executable memory regions.

That being said, it is difficult to tell why your code would produce an executable stack. Here is a list of possible causes and solutions:

  • When linking (or compiling and linking at the same time), pass the flag -z noexecstack to gcc or clang to forcefully disable executable stack, if possible.
  • If your project contains raw x86-64 assembly code, you may need to add the following line in the assembly .section .note.GNU-stack,"",@progbits. This line tells the compiler not to use executable stack;
  • If you wrote assembly code that explicit employs an executable stack, you shall pass the flag -z execstack when linking. This flag disables the warning. It should be noted that an executable stack is generally considered a security vulnerability;
  • The trickiest part is that although you have no desire of an executable stack, the compiler somehow deems it necessary. One possible causation (among many other) is nested function and function pointers. It is hard to spot these incidences; one method may be compiling all the files into assembly and spot for .section .note.GNU-stack,"x",@progbits, which implies the use of executable stack. In such cases passing the flag -z noexecstack would not suffice. Although the warning is suppressed and probably compilation and linking would succeed, runtime errors are likely to ensue.
like image 40
3 revs, 2 users 92%YuhaoHanHarry Avatar answered Jan 23 '26 05:01

3 revs, 2 users 92%YuhaoHanHarry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!