From: Andreas Krebbel Date: Tue, 4 Jul 2023 12:13:34 +0000 (+0200) Subject: Align linkerscript symbols according to ABI X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a5042543d819df8a76ebec8c4d715f244efbab0a;p=binutils-gdb.git Align linkerscript symbols according to ABI Apply ABI specific alignment to symbols generated in the default linker script. --- diff --git a/ld/emulparams/elf64_s390.sh b/ld/emulparams/elf64_s390.sh index 899efd7f532..d0a2a59a092 100644 --- a/ld/emulparams/elf64_s390.sh +++ b/ld/emulparams/elf64_s390.sh @@ -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. diff --git a/ld/emulparams/elf_s390.sh b/ld/emulparams/elf_s390.sh index cb1c6b5b04d..1b2fca3f937 100644 --- a/ld/emulparams/elf_s390.sh +++ b/ld/emulparams/elf_s390.sh @@ -12,3 +12,4 @@ GENERATE_SHLIB_SCRIPT=yes GENERATE_PIE_SCRIPT=yes NO_SMALL_DATA=yes IREL_IN_PLT= +SYMBOL_ABI_ALIGNMENT=2 diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc index 1e3c5aa8504..9e95e6b4162 100644 --- a/ld/scripttempl/elf.sc +++ b/ld/scripttempl/elf.sc @@ -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,19 +167,29 @@ if test -z "$GOT"; then GOTPLT=".got.plt ${RELOCATING-0} : { *(.got.plt)${RELOCATING+ *(.igot.plt)} }" fi fi + +def_symbol() +{ + if [ -z "${SYMBOL_ABI_ALIGNMENT}" ]; then + echo "${USER_LABEL_PREFIX}$1 = . " + else + echo "${USER_LABEL_PREFIX}$1 = ALIGN(${SYMBOL_ABI_ALIGNMENT})" + fi +} + REL_IFUNC=".rel.ifunc ${RELOCATING-0} : { *(.rel.ifunc) }" RELA_IFUNC=".rela.ifunc ${RELOCATING-0} : { *(.rela.ifunc) }" REL_IPLT=".rel.iplt ${RELOCATING-0} : { - ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_start = .);}} + ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN ($(def_symbol "__rel_iplt_start"));}} *(.rel.iplt) - ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_end = .);}} + ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN ($(def_symbol "__rel_iplt_end"));}} }" RELA_IPLT=".rela.iplt ${RELOCATING-0} : { - ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_start = .);}} + ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN ($(def_symbol "__rela_iplt_start"));}} *(.rela.iplt) - ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_end = .);}} + ${RELOCATING+${CREATE_PIC-PROVIDE_HIDDEN ($(def_symbol "__rela_iplt_end"));}} }" DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }" RODATA=".${RODATA_NAME} ${RELOCATING-0} : { *(.${RODATA_NAME}${RELOCATING+ .${RODATA_NAME}.* .gnu.linkonce.r.*}) }" @@ -267,23 +279,23 @@ else fi PREINIT_ARRAY=".preinit_array : { - ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_start = .);} + ${CREATE_SHLIB-PROVIDE_HIDDEN ($(def_symbol "__preinit_array_start"));} KEEP (*(.preinit_array)) - ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_end = .);} + ${CREATE_SHLIB-PROVIDE_HIDDEN ($(def_symbol "__preinit_array_end"));} }" INIT_ARRAY=".init_array : { - ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_start = .);} + ${CREATE_SHLIB-PROVIDE_HIDDEN ($(def_symbol "__init_array_start"));} ${SORT_INIT_ARRAY} KEEP (*(.init_array ${CTORS_IN_INIT_ARRAY})) - ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_end = .);} + ${CREATE_SHLIB-PROVIDE_HIDDEN ($(def_symbol "__init_array_end"));} }" FINI_ARRAY=".fini_array : { - ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_start = .);} + ${CREATE_SHLIB-PROVIDE_HIDDEN ($(def_symbol "__fini_array_start"));} ${SORT_FINI_ARRAY} KEEP (*(.fini_array ${DTORS_IN_FINI_ARRAY})) - ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_end = .);} + ${CREATE_SHLIB-PROVIDE_HIDDEN ($(def_symbol "__fini_array_end"));} }" CTOR=".ctors ${CONSTRUCTING-0} : { @@ -323,7 +335,7 @@ DTOR=".dtors ${CONSTRUCTING-0} : }" STACK=".stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} : { - ${RELOCATING+${USER_LABEL_PREFIX}_stack = .;} + ${RELOCATING+$(def_symbol "_stack");} *(.stack) ${RELOCATING+${STACK_SENTINEL}} }" @@ -494,16 +506,16 @@ cat >> ldscripts/dyntmp.$$ <