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/ldexp.h | |
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/ldexp.h')
-rw-r--r-- | ld/ldexp.h | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -133,6 +133,8 @@ enum relro_enum { exp_seg_relro_end, }; +struct lang_output_section_statement_struct; + typedef struct { enum phase_enum phase; @@ -176,10 +178,17 @@ struct ldexp_control { etree_value_type result; bfd_vma dot; - /* Current dot and section passed to ldexp folder. */ + /* Current dot and section passed to ldexp folder. SECTION will be + bfd_abs_section for expressions outside of an output section + statement. */ bfd_vma *dotp; asection *section; + /* Last output section statement. For expressions within an output + section statement, this will be the current output section + statement being processed. */ + struct lang_output_section_statement_struct *last_os; + /* State machine and results for DATASEG. */ seg_align_type dataseg; }; @@ -211,9 +220,10 @@ etree_type *exp_bigintop etree_type *exp_relop (asection *, bfd_vma); void exp_fold_tree - (etree_type *, asection *, bfd_vma *); + (etree_type *, struct lang_output_section_statement_struct *, + asection *, bfd_vma *); void exp_fold_tree_no_dot - (etree_type *); + (etree_type *, struct lang_output_section_statement_struct *); etree_type *exp_binop (int, etree_type *, etree_type *); etree_type *exp_trinop @@ -233,9 +243,9 @@ etree_type *exp_assert void exp_print_tree (etree_type *); bfd_vma exp_get_vma - (etree_type *, bfd_vma, char *); + (etree_type *, struct lang_output_section_statement_struct *, bfd_vma, char *); int exp_get_power - (etree_type *, char *); + (etree_type *, struct lang_output_section_statement_struct *, char *); fill_type *exp_get_fill (etree_type *, fill_type *, char *); bfd_vma exp_get_abs_int |