crust-firmware / crust

SCP (power management) firmware for sunxi SoCs
Other
155 stars 34 forks source link

Conditionally pass --no-warn-rwx-segments to ld to fix build with binutils 2.39 and newer #210

Closed NHellFire closed 1 year ago

NHellFire commented 1 year ago

Checks for existence of the argument, and only includes it if it exists to avoid breaking builds with older binutils.

Fixes #207

bill-auger commented 1 year ago

i can confirm that this patch allows the build to complete (gcc 12.2.1 + binutils 2.40)

but this does smell like a hack - perhaps the warning is indicating something important, which should be addressed, rather than ignored?

smaeul commented 1 year ago

No, the warning is not important. The AR100 does not have any MMU or MPU, so there is no way to mark memory ranges as read-only. Thus there is no benefit to splitting apart the code and writable data.

Another solution would be to pass -Wl,-z,max-page-size=4. Then, ld would put the code and data into separate ELF segments, but due to the small alignment, it wouldn't waste any space between them.

However, setting max-page-size causes another problem: ld decides to include the ELF program headers inside the PT_LOAD segment. It creates a segment starting slightly below FIRMWARE_BASE, such that the entry point still ends up at FIRMWARE_BASE after accounting for its offset in the ELF file. This would be bad if scp.elf was ever loaded (by e.g. a remoteproc driver), because the memory immediately below FIRMWARE_BASE is owned by a different firmware component (TF-A or U-Boot's secure monitor), and Crust is not allowed to overwrite it.

So I'm going to merge this --no-warn-rwx-segments change (merged as ade7ad311170b8a818741944d97489c887cd673f).

smaeul commented 1 year ago

Thanks again for coming up with a solution that works for everyone.