Skip to content
Snippets Groups Projects
Commit 3aed484a authored by Alessandro Di Federico's avatar Alessandro Di Federico
Browse files

Fix `li-csv-to-ld-options` warning message

We used to check if the value of `/proc/sys/vm/mmap_min_addr` is at
least as high as the minimum segment of the input binary. If this is not
the case the linked program will segfault at run-time without much
explanation.

However, in truth, we need to be able to map also the page before the
lowest page the original binary mapped. The main reason for this is to
have space for the (outer) ELF header.

It turns out that on many distros the default minimum value is
`0x10000`, which happens to be exactly the same address at which ARM
binaries mmap their lowest page. This lead to no warning, but a segfault
at run-time.

The AWK script now checks for the correct value, and also suggests the
correct value.

In the future, we might want to create a new segment for the outer ELF
header and position it elsewhere in the address space.
parent 4e871c6f
No related branches found
No related tags found
No related merge requests found
...@@ -24,10 +24,20 @@ END { ...@@ -24,10 +24,20 @@ END {
#printf "-fuse-ld=gold " #printf "-fuse-ld=gold "
printf "-fuse-ld=bfd " printf "-fuse-ld=bfd "
# Get the lowest page that can be allocate on this system
getline mmap_min < "/proc/sys/vm/mmap_min_addr" getline mmap_min < "/proc/sys/vm/mmap_min_addr"
if (min < mmap_min) {
print "WARNING: The minimum address to map is too low: " min " (minimum allowed: " mmap_min "). Please run:" > "/dev/stderr"; # We need to be able to allocate a page before the first one in the input
print "echo " min " | sudo tee /proc/sys/vm/mmap_min_addr" > "/dev/stderr"; # program
lowest_page = min - 4096
# If such page cannot be allocate, the linked program will crash at run-time,
# therefore, warn the user about this
if (lowest_page < mmap_min) {
print "WARNING: The minimum address to map is too low: " lowest_page \
" (minimum allowed: " mmap_min "). Please run:" > "/dev/stderr";
print "echo " lowest_page \
" | sudo tee /proc/sys/vm/mmap_min_addr" > "/dev/stderr";
} }
# If using gold omit these two lines # If using gold omit these two lines
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment