Commit: --rosegment: Restore alignment of text segment

Message ID 87frtabrba.fsf@redhat.com
State New
Headers
Series Commit: --rosegment: Restore alignment of text segment |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm warning Patch is already merged
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 warning Patch is already merged

Commit Message

Nick Clifton June 18, 2024, 8:14 a.m. UTC
  Hi Guys,

  *sigh* I have found another snafu with my --rosegment feature.
  I had disabled the alignment of the text segment in the on-disk
  image, on the assumption that the loader would be able to load
  a partial page into memory.  In turns out however that this is
  not correct, and that data following the text segment in the
  on-disk image can be loaded into the executable segment in
  memory.

  So I am checking in this patch to restore the alignment of the
  text segment in the on-disk image.  Which means that the file
  size increase when using '-z separate-code' is not alleviated
  as much. (It can still be slightly improved since --rosegment
  reduces the number of data segments).

Cheers
  Nick
  

Patch

diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc
index f1a61e7bcee..54716110b61 100644
--- a/ld/scripttempl/elf.sc
+++ b/ld/scripttempl/elf.sc
@@ -372,7 +372,7 @@  if test -z "$TINY_READONLY_SECTION"; then
     *ro*textonly*)
       ALL_TEXT_BEFORE_RO=" "
       SEPARATE_TEXT=" "
-      TEXT_SEGMENT_ALIGN=
+      TEXT_SEGMENT_ALIGN=". = ALIGN(${MAXPAGESIZE});"
       ;;
     *textonly*)
       SEPARATE_TEXT=" "