October 14, 2023

Orange Pi H3 -- 2023 update - linker warnings

I decided to take a look at some of my bare metal projects I put up on Github back in 2017 or so. There are a variety of issues with them. Not the least of the issues are that the Gnu linker is now giving a variety of warnings:
/usr/bin/arm-linux-gnu-ld: warning: start.o: missing .note.GNU-stack section implies executable stack
/usr/bin/arm-linux-gnu-ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
/usr/bin/arm-linux-gnu-ld: warning: interrupts.elf has a LOAD segment with RWX permissions

missing .note.GNU-stack section implies executable stack

I could just ingore these (the binary file works as well as it always did), but I don't like typing "make" and seeing errors or warnings. More importantly the warning that whatever it is it now doesn't like is deprecated and soon to be outlawed.

What this is all about (apparently) is a tightening of security. Allowing an executable stack (which I never intended nor asked for by the way) allows certain hacks to be done.

Note that this first error referenced "start.o" from "start.S". So the C source files are not causing any problem. This article discusses the whole business:

The article recommends adding a line like this:
.section  .note.GNU-stack, “x”, @progbits
This isn't quite right, and it doesn't say where to add such a line. What I did was to compile one of my C source files with the -S switch which outputs a ".s" file. It has the following as the last line of the file:
        .section        .note.GNU-stack,"",%progbits
When I add this as the last line of my "start.S" file, the warning goes away.

LOAD segment with RWX permissions

This leaves us with this error. The article suggests adding alignment instructions to the LDS file to cause text and data to be in different pages. This is probably the right thing for an executable that will run under linux where the kernel will set up various pages with different permissions. In my case I am doing bare metal programming, I am not using the MMU, so none of this really makes any sense.

To just make the linker shut up, we can use: "--no-warn-rwx-segments." We do this by adding an option like this (when using gcc to link) to the linker line:

-Wl,--no-warn-rwx-segments
This works just fine and now I can compile and link without warnings. If I am directly invoking "ld" to link, I use:
ld --no-warn-rwx-segments


Have any comments? Questions? Drop me a line!

Tom's electronics pages / tom@mmto.org