Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing linker warnings #2012

Merged
merged 3 commits into from
Mar 23, 2024
Merged

Fixing linker warnings #2012

merged 3 commits into from
Mar 23, 2024

Conversation

francescolavra
Copy link
Member

This changeset fixes linker warnings that appeared starting with release 2.39 of the GNU binutils.
In addition, it amends the x86 bootloader linker script so that the size of the bootloader binary file is decreased by around 2%.

Closes #1870 and #2010

Starting with release 2.39 of the GNU Binutils, the ld linker warns
with "missing .note.GNU-stack section implies executable stack" if
it encounters an object file without a .note.GNU-stack section, and
with "relocation in read-only section" if it encounters an object
file containing a text relocation. In the both the kernel and the
various bootloaders, such object files exist and are those built
from assembly source files.
The `-z noexecstack` linker option silences the first warning (and
makes the linker assume that the output executable does not need an
executable stack).
The `-z notext` option silences the second warning (which does not
reveal an actual issue, because the kernel is able to apply text
relocations when doing KASLR).

#1870
Starting with release 2.39 of the GNU Binutils, the linker warns
when creating an ELF file containing a LOAD segment with RWX
permissions (#1870). With
the curent linker script for the x86 bootloader, the resulting ELF
file contains such a segment.
This change adds a PHDRS directive to the linker script and maps
the different sections to the appropriate segments, so that no
LOAD segments with RWX permissions exist in the stage2.elf file.
This does not affet the final binary file of the bootloader, but
silences the above warning.
In addition, the SECTIONS directive of the linker script has been
fixed so that all the input sections are mapped to the output
sections specified in the script; this decreases by around 2% the
size of the bootloader binary file.

Closes #2010
This change amends the linker scripts for the klibs so that each
klib ELF file has 3 segments: a text segment with read and execute
permissions, a data segment with read-only permissions, and a data
segment with read/write permissions. This avoids mapping an entire
klib image with both write and execute permissions when the kernel
loads a klib.
In addition, the SECTIONS directive in the linker scripts has been
fixed so that all the read-only input sections are mapped to the
.text and .rodata output sections; this decreases the size of the
klib ELF files.
@francescolavra francescolavra merged commit c641f82 into master Mar 23, 2024
5 checks passed
@francescolavra francescolavra deleted the fix/ld-warnings branch March 23, 2024 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

investigate(build): warnings - gcc-12.2, ld-2.40
2 participants