Skip to content

Commit

Permalink
arm/aa64: fix the size of .rela* sections
Browse files Browse the repository at this point in the history
The previous commit(*) merged .rel* and .dyn* into .rodata, and this
made ld to generate the wrong size for .rela* sections that covered
other unrelated sections. When the EFI image was loaded, _relocate()
went through the unexpected data and may cause unexpected crash.
This commit moves .rel* and .dyn* out of .rodata in the ld script but
also moves the related variables, such as _evrodata, _rodata_size,
and _rodata_vsize, to the end of the new .dyn section, so that the
crafted pe-coff section header for .rodata still covers our new
.rela and .dyn sections.

(*) 212ba30 ("arm/aa64 targets: put .rel* and .dyn* in .rodata")

Fix issue: rhboot#371

Signed-off-by: Gary Lin <[email protected]>
  • Loading branch information
lcp committed Jun 17, 2021
1 parent 05875f3 commit 9828f65
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ ifneq ($(OBJCOPY_GTE224),1)
endif
$(OBJCOPY) -D -j .text -j .sdata -j .data -j .data.ident \
-j .dynamic -j .rodata -j .rel* \
-j .rela* -j .reloc -j .eh_frame \
-j .rela* -j .dyn -j .reloc -j .eh_frame \
-j .vendor_cert -j .sbat \
$(FORMAT) $< $@
./post-process-pe -vv $@
Expand All @@ -263,7 +263,7 @@ ifneq ($(OBJCOPY_GTE224),1)
endif
$(OBJCOPY) -D -j .text -j .sdata -j .data \
-j .dynamic -j .rodata -j .rel* \
-j .rela* -j .reloc -j .eh_frame -j .sbat \
-j .rela* -j .dyn -j .reloc -j .eh_frame -j .sbat \
-j .debug_info -j .debug_abbrev -j .debug_aranges \
-j .debug_line -j .debug_str -j .debug_ranges \
-j .note.gnu.build-id \
Expand Down
24 changes: 16 additions & 8 deletions elf_aarch64_efi.lds
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,29 @@ SECTIONS
.rodata :
{
_rodata = .;
*(.rela.dyn)
*(.rela.plt)
*(.rela.got)
*(.rela.data)
*(.rela.data*)

*(.rodata*)
*(.srodata)
*(.dynsym)
*(.dynstr)
. = ALIGN(16);
*(.note.gnu.build-id)
. = ALIGN(4096);
*(.vendor_cert)
*(.data.ident)
. = ALIGN(4096);
}
. = ALIGN(4096);
.rela :
{
*(.rela.dyn)
*(.rela.plt)
*(.rela.got)
*(.rela.data)
*(.rela.data*)
}
. = ALIGN(4096);
.dyn :
{
*(.dynsym)
*(.dynstr)
_evrodata = .;
. = ALIGN(4096);
}
Expand Down
24 changes: 16 additions & 8 deletions elf_arm_efi.lds
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,29 @@ SECTIONS
.rodata :
{
_rodata = .;
*(.rel.dyn)
*(.rel.plt)
*(.rel.got)
*(.rel.data)
*(.rel.data*)

*(.rodata*)
*(.srodata)
*(.dynsym)
*(.dynstr)
. = ALIGN(16);
*(.note.gnu.build-id)
. = ALIGN(4096);
*(.vendor_cert)
*(.data.ident)
. = ALIGN(4096);
}
. = ALIGN(4096);
.rela :
{
*(.rela.dyn)
*(.rela.plt)
*(.rela.got)
*(.rela.data)
*(.rela.data*)
}
. = ALIGN(4096);
.dyn :
{
*(.dynsym)
*(.dynstr)
_evrodata = .;
. = ALIGN(4096);
}
Expand Down

0 comments on commit 9828f65

Please sign in to comment.