Support NEXT_SECTION in ALIGNOF and SIZEOF
authorAlan Modra <amodra@gmail.com>
Fri, 14 Jul 2023 23:16:35 +0000 (08:46 +0930)
committerAlan Modra <amodra@gmail.com>
Sun, 16 Jul 2023 22:47:44 +0000 (08:17 +0930)
commit63e8fb86255ac97c31d368221be18850ad53039d
tree508341e8d8cdeab39688128e43308332161307f6
parent5c77898d60cfea469a86fc6026f51b4a6d8e7444
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.
19 files changed:
ld/ld.texi
ld/ldexp.c
ld/ldexp.h
ld/ldlang.c
ld/scripttempl/arclinux.sc
ld/scripttempl/elf.sc
ld/scripttempl/elf64bpf.sc
ld/scripttempl/elf64hppa.sc
ld/scripttempl/elf_chaos.sc
ld/scripttempl/elfarc.sc
ld/scripttempl/elfd10v.sc
ld/scripttempl/elfxtensa.sc
ld/scripttempl/epiphany_4x4.sc
ld/scripttempl/iq2000.sc
ld/scripttempl/mep.sc
ld/scripttempl/nds32elf.sc
ld/scripttempl/xstormy16.sc
ld/testsuite/ld-x86-64/pe-x86-64-5.od
ld/testsuite/ld-x86-64/pe-x86-64-5.rd