ld - Add SYMBOL_ABI_ALIGNMENT variable and apply to __bss_start
Checks
Commit Message
Currently not specific alignment is applied to the __bss_start
symbol. However, on s390x we require every symbol to be on an even
address. The patch introduces a new variable for the elf.sc template
which allows to specify such an symbol alignment requirement.
ld/
* scripttempl/elf.sc: New variable SYMBOL_ABI_ALIGNMENT. Apply
to __bss_start.
* emulparams/elf_s390.sh: Set SYMBOL_ABI_ALIGNMENT to 2.
* emulparams/elf64_s390.sh: Likewise.
---
ld/emulparams/elf64_s390.sh | 1 +
ld/emulparams/elf_s390.sh | 1 +
ld/scripttempl/elf.sc | 5 ++++-
3 files changed, 6 insertions(+), 1 deletion(-)
Comments
Hi Andreas,
> Currently not specific alignment is applied to the __bss_start
> symbol. However, on s390x we require every symbol to be on an even
> address. The patch introduces a new variable for the elf.sc template
> which allows to specify such an symbol alignment requirement.
This patch looks good, but I see one issue - there are lot more symbols
provided by the elf.sc template than just __bss_start. So if an ABI
requires symbols to be aligned, then that should apply to all symbols,
right ?
Actually there is one other thing. Rather than doing:
${RELOCATING+. = ALIGN(${SYMBOL_ABI_ALIGNMENT});}
${RELOCATING+${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}__bss_start = .${CREATE_SHLIB+)};}
Wouldn't it make more sense to do:
${RELOCATING+${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}__bss_start = ALIGN (.${CREATE_SHLIB+), ${SYMBOL_ABI_ALIGNMENT});}
Ie making it clear that the alignment is being applied to the symbol.
It might even be possible to create a macro to do all of this
USER_LABEL_PREFIX and ALIGN munging, so that it does not have
to be repeated countless times in the elf.sc file. I have not
actually checked to see if this is possible, but it would be
nice if it could be done.
Cheers
Nick
On 6/27/23 16:14, Nick Clifton wrote:
> Hi Andreas,
>
>> Currently not specific alignment is applied to the __bss_start
>> symbol. However, on s390x we require every symbol to be on an even
>> address. The patch introduces a new variable for the elf.sc template
>> which allows to specify such an symbol alignment requirement.
>
> This patch looks good, but I see one issue - there are lot more symbols
> provided by the elf.sc template than just __bss_start. So if an ABI
> requires symbols to be aligned, then that should apply to all symbols,
> right ?
I think most of the other symbols are implicitly aligned because of other effects. The same way it
used to be for __bss_start actually. GCC for Z pads the .data section size to a multiple of 8 but
LLVM doesn't. But you are right. In order to make it more robust we should apply it to the other
symbols as well. I'll have a look.
> Actually there is one other thing. Rather than doing:
>
> ${RELOCATING+. = ALIGN(${SYMBOL_ABI_ALIGNMENT});}
> ${RELOCATING+${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}__bss_start = .${CREATE_SHLIB+)};}
>
> Wouldn't it make more sense to do:
>
> ${RELOCATING+${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}__bss_start = ALIGN (.${CREATE_SHLIB+), ${SYMBOL_ABI_ALIGNMENT});}
Yes, that's better.
> Ie making it clear that the alignment is being applied to the symbol.
>
> It might even be possible to create a macro to do all of this
> USER_LABEL_PREFIX and ALIGN munging, so that it does not have
> to be repeated countless times in the elf.sc file. I have not
> actually checked to see if this is possible, but it would be
> nice if it could be done.
Agreed. I'm not that familiar with what is possible in these files but I'll try to come up with
something.
Thanks for having a look!
Bye,
Andreas
>
> Cheers
> Nick
>
@@ -17,6 +17,7 @@ EXTRA_EM_FILE=s390
IREL_IN_PLT=
SEPARATE_GOTPLT=0
test -z "$RELRO" && unset SEPARATE_GOTPLT
+SYMBOL_ABI_ALIGNMENT=2
# Treat a host that matches the target with the possible exception of "x"
# in the name as if it were native.
@@ -12,3 +12,4 @@ GENERATE_SHLIB_SCRIPT=yes
GENERATE_PIE_SCRIPT=yes
NO_SMALL_DATA=yes
IREL_IN_PLT=
+SYMBOL_ABI_ALIGNMENT=2
@@ -78,6 +78,8 @@
# USER_LABEL_PREFIX - prefix to add to user-visible symbols.
# RODATA_NAME, SDATA_NAME, SBSS_NAME, BSS_NAME - base parts of names
# for standard sections, without initial "." or suffixes.
+# SYMBOL_ABI_ALIGNMENT - minimum alignment in bytes which needs to be
+# applied to every symbol definition
#
# When adding sections, do note that the names of some sections are used
# when specifying the start address of the next.
@@ -165,6 +167,7 @@ if test -z "$GOT"; then
GOTPLT=".got.plt ${RELOCATING-0} : { *(.got.plt)${RELOCATING+ *(.igot.plt)} }"
fi
fi
+test -z "${SYMBOL_ABI_ALIGNMENT}" && SYMBOL_ABI_ALIGNMENT=1
REL_IFUNC=".rel.ifunc ${RELOCATING-0} : { *(.rel.ifunc) }"
RELA_IFUNC=".rela.ifunc ${RELOCATING-0} : { *(.rela.ifunc) }"
REL_IPLT=".rel.iplt ${RELOCATING-0} :
@@ -678,7 +681,7 @@ cat <<EOF
${DATA_SDATA-${OTHER_SDATA_SECTIONS}}
${RELOCATING+${DATA_END_SYMBOLS-${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}_edata = .${CREATE_SHLIB+)}; PROVIDE (${USER_LABEL_PREFIX}edata = .);}}
${PERSISTENT}
- ${RELOCATING+. = .;}
+ ${RELOCATING+. = ALIGN(${SYMBOL_ABI_ALIGNMENT});}
${RELOCATING+${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}__bss_start = .${CREATE_SHLIB+)};}
${RELOCATING+${OTHER_BSS_SYMBOLS}}
${DATA_SDATA-${SBSS}}