diff options
author | Alan Modra <amodra@gmail.com> | 2023-07-15 08:46:35 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-07-17 08:17:44 +0930 |
commit | 63e8fb86255ac97c31d368221be18850ad53039d (patch) | |
tree | 508341e8d8cdeab39688128e43308332161307f6 /ld/scripttempl | |
parent | 5c77898d60cfea469a86fc6026f51b4a6d8e7444 (diff) | |
download | gdb-63e8fb86255ac97c31d368221be18850ad53039d.zip gdb-63e8fb86255ac97c31d368221be18850ad53039d.tar.gz gdb-63e8fb86255ac97c31d368221be18850ad53039d.tar.bz2 |
Support NEXT_SECTION in ALIGNOF and SIZEOF
This patch is aimed at making __bss_start properly aligned with the
first of any bss-style sections following. Most of the work here
involves keeping track of the last output section seen when processing
the linker script.
You can almost align __bss_start properly by using
${RELOCATING+. = ALIGN(${DATA_SDATA-${NO_SMALL_DATA-ALIGNOF(.${SBSS_NAME}) != 0 ? ALIGNOF(.${SBSS_NAME}) : }}${BSS_PLT+ALIGNOF(.plt) != 0 ? ALIGNOF(.plt) : }ALIGNOF(.${BSS_NAME}));}
and changing every place that defines NO_SMALL_DATA to use " ", but
having two .plt sections (marked SPECIAL) on some backends foils that
idea. The problem is that you only want to pick up the following
.plt, not the one preceeding __bss_start in the data segment if the
backend decides that is the proper .plt section.
Perhaps that could be fixed too, but I decided instead to extend the
linker script a little. THIS_SECTION and PREV_SECTION could easily be
added too.
* ld.texi (ALIGNOF, SIZEOF): Update and mention NEXT_SECTION.
* ldexp.c (output_section_find): New function.
(fold_name <ALIGNOF, SIZEOF>): Use output_section_find.
(exp_fold_tree): Add os parameter. Adjust all calls.
(exp_fold_tree_no_dot, exp_get_vma, exp_get_power): Likewise.
* ldexp.h (struct ldexp_control): Add last_os.
(exp_fold_tree, exp_fold_tree_no_dot): Update prototypes.
(exp_get_vma, exp_get_power): Likewise.
* ldlang.c: Pass last output section to expression folder
calls throughout file.
(open_input_bfds): Add os parameter to track last os seen.
(lang_size_sections_1): Rename output_section_statement param
to current_os. Track last os.
(lang_do_assignments_1): Track last os.
* scripttempl/arclinux.sc: Align to ALIGNOF NEXT_SECTION
before defining __bss_start.
* scripttempl/elf.sc: Likewise.
* scripttempl/elf64bpf.sc: Likewise.
* scripttempl/elf64hppa.sc: Likewise.
* scripttempl/elf_chaos.sc: Likewise.
* scripttempl/elfarc.sc: Likewise.
* scripttempl/elfd10v.sc: Likewise.
* scripttempl/elfxtensa.sc: Likewise.
* scripttempl/epiphany_4x4.sc: Likewise.
* scripttempl/iq2000.sc: Likewise.
* scripttempl/mep.sc: Likewise.
* scripttempl/nds32elf.sc: Likewise.
* scripttempl/xstormy16.sc: Likewise.
* testsuite/ld-x86-64/pe-x86-64-5.od: Update expected __bss_start.
* testsuite/ld-x86-64/pe-x86-64-5.rd: Likewise.
Diffstat (limited to 'ld/scripttempl')
-rw-r--r-- | ld/scripttempl/arclinux.sc | 2 | ||||
-rw-r--r-- | ld/scripttempl/elf.sc | 2 | ||||
-rw-r--r-- | ld/scripttempl/elf64bpf.sc | 2 | ||||
-rw-r--r-- | ld/scripttempl/elf64hppa.sc | 1 | ||||
-rw-r--r-- | ld/scripttempl/elf_chaos.sc | 1 | ||||
-rw-r--r-- | ld/scripttempl/elfarc.sc | 1 | ||||
-rw-r--r-- | ld/scripttempl/elfd10v.sc | 1 | ||||
-rw-r--r-- | ld/scripttempl/elfxtensa.sc | 1 | ||||
-rw-r--r-- | ld/scripttempl/epiphany_4x4.sc | 2 | ||||
-rw-r--r-- | ld/scripttempl/iq2000.sc | 1 | ||||
-rw-r--r-- | ld/scripttempl/mep.sc | 1 | ||||
-rw-r--r-- | ld/scripttempl/nds32elf.sc | 2 | ||||
-rw-r--r-- | ld/scripttempl/xstormy16.sc | 1 |
13 files changed, 13 insertions, 5 deletions
diff --git a/ld/scripttempl/arclinux.sc b/ld/scripttempl/arclinux.sc index 20429df..3c27625 100644 --- a/ld/scripttempl/arclinux.sc +++ b/ld/scripttempl/arclinux.sc @@ -613,7 +613,7 @@ cat <<EOF ${DATA_SDATA-${SDATA}} ${DATA_SDATA-${OTHER_SDATA_SECTIONS}} ${RELOCATING+${DATA_END_SYMBOLS-${USER_LABEL_PREFIX}_edata = .; PROVIDE (${USER_LABEL_PREFIX}edata = .);}} - ${RELOCATING+. = .;} + ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));} ${RELOCATING+${USER_LABEL_PREFIX}__bss_start = .;} ${RELOCATING+${OTHER_BSS_SYMBOLS}} ${DATA_SDATA-${SBSS}} diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc index 82de4ed..fe921cd 100644 --- a/ld/scripttempl/elf.sc +++ b/ld/scripttempl/elf.sc @@ -689,7 +689,7 @@ cat <<EOF ${RELOCATING+${SYMBOL_ABI_ALIGNMENT+. = ALIGN(${SYMBOL_ABI_ALIGNMENT});}} ${RELOCATING+${DATA_END_SYMBOLS-${CREATE_SHLIB+PROVIDE (}$(def_symbol "_edata")${CREATE_SHLIB+)}; PROVIDE ($(def_symbol "edata"));}} ${PERSISTENT} - ${RELOCATING+. = .;} + ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));} ${RELOCATING+${CREATE_SHLIB+PROVIDE (}$(def_symbol "__bss_start")${CREATE_SHLIB+)};} ${RELOCATING+${OTHER_BSS_SYMBOLS}} ${DATA_SDATA-${SBSS}} diff --git a/ld/scripttempl/elf64bpf.sc b/ld/scripttempl/elf64bpf.sc index 7415458..07a0726 100644 --- a/ld/scripttempl/elf64bpf.sc +++ b/ld/scripttempl/elf64bpf.sc @@ -636,7 +636,7 @@ cat <<EOF ${DATA_SDATA-${SDATA}} ${DATA_SDATA-${OTHER_SDATA_SECTIONS}} ${RELOCATING+${DATA_END_SYMBOLS-${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}_edata = .${CREATE_SHLIB+)}; PROVIDE (${USER_LABEL_PREFIX}edata = .);}} - ${RELOCATING+. = .;} + ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));} ${RELOCATING+${CREATE_SHLIB+PROVIDE (}${USER_LABEL_PREFIX}__bss_start = .${CREATE_SHLIB+)};} ${RELOCATING+${OTHER_BSS_SYMBOLS}} ${DATA_SDATA-${SBSS}} diff --git a/ld/scripttempl/elf64hppa.sc b/ld/scripttempl/elf64hppa.sc index e85dd39..b3be5a2 100644 --- a/ld/scripttempl/elf64hppa.sc +++ b/ld/scripttempl/elf64hppa.sc @@ -490,6 +490,7 @@ cat <<EOF ${SDATA} ${OTHER_SDATA_SECTIONS} ${RELOCATING+${DATA_END_SYMBOLS-${USER_LABEL_PREFIX}_edata = .; PROVIDE (${USER_LABEL_PREFIX}edata = .);}} + ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));} ${RELOCATING+__bss_start = .;} ${RELOCATING+${OTHER_BSS_SYMBOLS}} ${SBSS} diff --git a/ld/scripttempl/elf_chaos.sc b/ld/scripttempl/elf_chaos.sc index 72f91c9..88b573c 100644 --- a/ld/scripttempl/elf_chaos.sc +++ b/ld/scripttempl/elf_chaos.sc @@ -303,6 +303,7 @@ cat <<EOF ${OTHER_SDATA_SECTIONS} ${RELOCATING+_edata = .;} ${RELOCATING+PROVIDE (edata = .);} + ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));} ${RELOCATING+__bss_start = .;} ${RELOCATING+${OTHER_BSS_SYMBOLS}} ${SBSS} diff --git a/ld/scripttempl/elfarc.sc b/ld/scripttempl/elfarc.sc index 57cd0a5..1ae0248 100644 --- a/ld/scripttempl/elfarc.sc +++ b/ld/scripttempl/elfarc.sc @@ -365,6 +365,7 @@ cat <<EOF ${OTHER_SDATA_SECTIONS} ${RELOCATING+_edata = .;} ${RELOCATING+PROVIDE (edata = .);} + ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));} ${RELOCATING+__bss_start = .;} ${RELOCATING+${OTHER_BSS_SYMBOLS}} ${SBSS} diff --git a/ld/scripttempl/elfd10v.sc b/ld/scripttempl/elfd10v.sc index e52aaed..316fa89 100644 --- a/ld/scripttempl/elfd10v.sc +++ b/ld/scripttempl/elfd10v.sc @@ -156,6 +156,7 @@ SECTIONS ${RELOCATING+_edata = .;} ${RELOCATING+PROVIDE (edata = .);} + ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));} ${RELOCATING+__bss_start = .;} .sbss ${RELOCATING-0} : { *(.sbss)${RELOCATING+ *(.scommon)} } ${RELOCATING+ >DATA} .bss ${RELOCATING-0} : diff --git a/ld/scripttempl/elfxtensa.sc b/ld/scripttempl/elfxtensa.sc index 7c71525..9c85d15 100644 --- a/ld/scripttempl/elfxtensa.sc +++ b/ld/scripttempl/elfxtensa.sc @@ -500,6 +500,7 @@ cat <<EOF ${SDATA} ${OTHER_SDATA_SECTIONS} ${RELOCATING+${DATA_END_SYMBOLS-${USER_LABEL_PREFIX}_edata = .; PROVIDE (${USER_LABEL_PREFIX}edata = .);}} + ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));} ${RELOCATING+__bss_start = .;} ${RELOCATING+${OTHER_BSS_SYMBOLS}} ${SBSS} diff --git a/ld/scripttempl/epiphany_4x4.sc b/ld/scripttempl/epiphany_4x4.sc index 0f4e74f..ee253af 100644 --- a/ld/scripttempl/epiphany_4x4.sc +++ b/ld/scripttempl/epiphany_4x4.sc @@ -578,7 +578,7 @@ cat <<EOF /* Align ___bss_start and _end to a multiple of 8 so that we can use strd to clear bss. N.B., without adding any extra alignment, we would have to clear the bss byte by byte. */ - ${RELOCATING+. = ALIGN(8);} + ${RELOCATING+. = ALIGN(MAX(8,ALIGNOF(NEXT_SECTION)));} ${RELOCATING+___bss_start = .;} ${RELOCATING+${OTHER_BSS_SYMBOLS}} ${SBSS} diff --git a/ld/scripttempl/iq2000.sc b/ld/scripttempl/iq2000.sc index 47bd777..c3d3620 100644 --- a/ld/scripttempl/iq2000.sc +++ b/ld/scripttempl/iq2000.sc @@ -373,6 +373,7 @@ cat <<EOF ${RELOCATING+${OTHER_SDATA_SECTIONS}} ${RELOCATING+_edata = .;} ${RELOCATING+PROVIDE (edata = .);} + ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));} ${RELOCATING+__bss_start = .;} ${RELOCATING+${OTHER_BSS_SYMBOLS}} .sbss ${RELOCATING-0} : diff --git a/ld/scripttempl/mep.sc b/ld/scripttempl/mep.sc index 6b80c36..d49f848 100644 --- a/ld/scripttempl/mep.sc +++ b/ld/scripttempl/mep.sc @@ -385,6 +385,7 @@ cat <<EOF ${OTHER_SDATA_SECTIONS} ${RELOCATING+_edata = .;} ${RELOCATING+PROVIDE (edata = .);} + ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));} ${RELOCATING+__bss_start = .;} ${RELOCATING+${OTHER_BSS_SYMBOLS}} ${SBSS} diff --git a/ld/scripttempl/nds32elf.sc b/ld/scripttempl/nds32elf.sc index 9645e80..36d04cd 100644 --- a/ld/scripttempl/nds32elf.sc +++ b/ld/scripttempl/nds32elf.sc @@ -557,7 +557,7 @@ cat <<EOF ${OTHER_SDATA_SECTIONS} ${RELOCATING+. = ALIGN(4);} ${RELOCATING+${DATA_END_SYMBOLS-${USER_LABEL_PREFIX}_edata = .; PROVIDE (${USER_LABEL_PREFIX}edata = .);}} - ${RELOCATING+. = .;} + ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));} ${RELOCATING+${USER_LABEL_PREFIX}__bss_start = .;} ${RELOCATING+${OTHER_BSS_SYMBOLS}} ${SBSS} diff --git a/ld/scripttempl/xstormy16.sc b/ld/scripttempl/xstormy16.sc index ccae0a2..b29f720 100644 --- a/ld/scripttempl/xstormy16.sc +++ b/ld/scripttempl/xstormy16.sc @@ -143,6 +143,7 @@ SECTIONS ${RELOCATING+${OTHER_GOT_SECTIONS}} ${RELOCATING+_edata = .;} ${RELOCATING+PROVIDE (edata = .);} + ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));} ${RELOCATING+__bss_start = .;} ${RELOCATING+${OTHER_BSS_SYMBOLS}} .bss ${RELOCATING-0} : |