public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* Linker scripts use of "-z common-page-size=0x20" etc.
@ 2023-04-03 20:33 Rebecca Cran
  2023-04-03 20:58 ` Marvin Häuser
  2023-04-04  7:22 ` Ard Biesheuvel
  0 siblings, 2 replies; 8+ messages in thread
From: Rebecca Cran @ 2023-04-03 20:33 UTC (permalink / raw)
  To: Pedro Falcato, Marvin Häuser, Liming Gao, Ard Biesheuvel
  Cc: devel@edk2.groups.io

As part of my work on the toolchain definitions, I've come across a 
situation where ld.lld fails to align sections correctly, due to it 
being invoked via clang with the '-n' option, which causes GenFw to fail 
with "Section address not aligned to its own alignment.".

The following messages are printed:


ld.lld: warning: -z common-page-size set, but paging disabled by omagic 
or nmagic ld.lld: warning: address (0x558) of section .data is not a 
multiple of alignment (16)

I tracked the problem down to GccBase.lds and ClangBase.lds, which have:

/* * The alignment of the .data section should be less than or equal to 
the * alignment of the .text section. This ensures that the relative 
offset * between these sections is the same in the ELF and the PE/COFF 
versions of * this binary. */ .data ALIGN(ALIGNOF(.text)) : 
ALIGN(CONSTANT(COMMONPAGESIZE)) { *(.data .data.* .gnu.linkonce.d.*) 
*(.bss .bss.*) }

I can work around the problem by removing "ALIGN(ALIGNOF(.text)", but 
I'm wondering if our use of COMMONPAGESIZE/MAXPAGESIZE is correct.


We pass in a value of 0x20, 0x40 or 0x1000 to "-z common-page-size" with 
0x20 being the most common value.

Given the page size of the target will never be 32 bytes, the following 
comment on https://reviews.llvm.org/D61688 makes sense:


"There is at least one linkerscript in Tianocore edk2 that (ab)uses -n 
-z common-page-size=0x20 to use CONSTANT(COMMONPAGESIZE) as if it were a 
preprocessor macro set with -D in the compiler. The usual approach to 
this is to pre-process the linkerscript."


I'm wondering what the correct approach is here: should we do something 
similar to how we set PECOFF_HEADER_SIZE and define a SECTION_ALIGNMENT 
symbol? Or, as discussed on Discord should we just use 
CONSTANT(MAXPAGESIZE) and ignore how it's normally used to specify the 
maximum allowable page size for an executable?


-- 
Rebecca Cran


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-04-04 14:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-03 20:33 Linker scripts use of "-z common-page-size=0x20" etc Rebecca Cran
2023-04-03 20:58 ` Marvin Häuser
2023-04-03 22:56   ` Rebecca Cran
2023-04-04  7:22 ` Ard Biesheuvel
2023-04-04  7:43   ` Marvin Häuser
2023-04-04 11:10   ` Rebecca Cran
2023-04-04 14:03     ` Ard Biesheuvel
2023-04-04 14:10       ` Marvin Häuser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox