Commit Graph

492 Commits

Author SHA1 Message Date
John David Anglin
a82e3815df hppa: Implement PA 2.0 symbolic relocations for long displacements
The PA 2.0 architecture introduced several new load and store
instructions with long displacements.  These include floating
point loads and stores for word mode, and integer and floating
point loads and stores for double words.  Currently, ld does
not correctly support symbolic relocations for these instructions.

If these are used, ld applies the standard R_PARISC_DPREL14R
relocation and corrupts the instruction.  This change uses
bfd_hppa_insn2fmt to determine the correct relocation format.

We need to check the computed displacement as the immediate
value used in these instruction must be a multiple of 4 or 8
depending on whether the access is for a word or double word.

A misaligned offset can potentially occur if the symbol is not
properly aligned or if $global$ (the global pointer) is not
double word aligned.  $global$ is provided as a .data section
start symbol.  The patch adjusts elf.sc and hppalinux.sh to
align .data to a 8-byte boundary in non-shared and non-pie
links.

2024-04-01  John David Anglin  <danglin@gcc.gnu.org>

	PR ld/31503

bfd/ChangeLog:

	* elf32-hppa.c (final_link_relocate): Output

ld/ChangeLog:

	* emulparams/hppalinux.sh (DATA_SECTION_ALIGNMENT): Define.
	* scripttempl/elf.sc: Align .data section to DATA_SECTION_ALIGNMENT
	when relocating.
2024-04-01 23:00:52 +00:00
Georg-Johann Lay
24f5deb64d PR31124: Addendum: Remove PROVIDE of __flmap_init_label, __flmap.
Supply these symbols as computed by the linker scripts, even when there are weak definitions.
PR 31124
  * scripttempl/avr.sc (__flmap, __flmap_init_label): Remove PROVIDE.
2024-01-31 11:23:20 +00:00
H.J. Lu
c873acc5fe ld: Remove scripttempl/elf_chaos.sc
scripttempl/elf_chaos.sc is unused.  Remove it.

	* scripttempl/elf_chaos.sc: Removed.
2024-01-19 08:05:49 -08:00
H.J. Lu
dbca3300ea Remove hosts/mipsbsd.h and scripttempl/mipsbsd.sc
Remove hosts/mipsbsd.h and scripttempl/mipsbsd.sc which are unused
after

commit 3596d8ceb2
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Apr 18 15:39:34 2018 +0930

    Remove mips aout, coff, and pe support

bfd/

	* hosts/mipsbsd.h: Removed.

ld/

	* scripttempl/mipsbsd.sc: Removed.
2024-01-19 07:25:31 -08:00
Alan Modra
fd67aa1129 Update year range in copyright notice of binutils files
Adds two new external authors to etc/update-copyright.py to cover
bfd/ax_tls.m4, and adds gprofng to dirs handled automatically, then
updates copyright messages as follows:

1) Update cgen/utils.scm emitted copyrights.
2) Run "etc/update-copyright.py --this-year" with an extra external
   author I haven't committed, 'Kalray SA.', to cover gas testsuite
   files (which should have their copyright message removed).
3) Build with --enable-maintainer-mode --enable-cgen-maint=yes.
4) Check out */po/*.pot which we don't update frequently.
2024-01-04 22:58:12 +10:30
Georg-Johann Lay
d51cd0f64c PR31177: Let region text start at __TEXT_REGION_ORIGIN___
The start of MEMORY region text currently starts hard-coded at 0.

The linker can produce more exact diagnostics when it knows the exact placements of the memory regions.

For some old devices, program memory starts at 0x8000, so allow to specify program memory start at __TEXT_REGION_ORIGIN__ similar to how the data region is described.

If ok, please apply to master.
This one is also fine to back-port.

Johann

--

AVR: Use __TEXT_REGION_ORIGIN__ as start for MEMORY region text.

ld/
	PR 31177
	* scripttempl/avr.sc (__TEXT_REGION_ORIGIN__): New symbol.
	(MEMORY): Use as start address for the text region.
2023-12-18 09:50:51 +00:00
Georg-Johann Lay
a5a863b4b9 Addendum to PR31124
This is a small addendum to PR31124 "rodata in flash for
more AVR devices".

It adds some symbols so the startup code can set a lock
on the FLMAP bit field as specified by the user.

New symbols are introduced because otherwise, all the
computations / decisions would have to be performed at
run-time.

It approved, please apply to master.

Johann

--

ld/
	PR 31124
	* scripttempl/avr.sc: Adjust comments.
	[MAYBE_FLMAP]: Add symbols __flmap_value and __flmap_value_with_lock.
	Remove __flmap_lsl4.
2023-12-15 09:52:55 +00:00
Georg-Johann Lay
0804d18a02 Support rodata in flash for more AVR devices
PR 31124
  * Makefile.am (ALL_EMULATION_SOURCES): Add eavrxmega2_flmap.c and eavrxmega4_flmap.c.
  * Makefile.in: Regenerate.
  * configure.tgt: Add eavrxmega2_flmap and eavrxmega4_flmap to avr's targ_extra_emuls list.
  * emulparams/avrxmega2.sh (MAYBE_FLMAP): Define.
  * emulparams/avrxmega2_flmap.sh: New file.
  * emulparams/avrxmega4.sh (MAYBE_FLMAP): Define.
  * emulparams/avrxmega4_flmap.sh: New file.
  * scripttempl/avr.sc: Add support for HAVE_FLMAP.
2023-12-12 11:29:16 +00:00
Claudiu Zissulescu
7f2b40892a Revert "arc: Add new linker emulation and scripts for ARCv3 ISA."
This reverts commit 4deb1ee57f.
2023-09-25 17:02:55 +03:00
Claudiu Zissulescu
4deb1ee57f arc: Add new linker emulation and scripts for ARCv3 ISA.
Add ARCv3's linker bits. Remove obsolete tests.

ld/
xxxx-xx-xx  Claudiu Zissulescu  <claziss@synopsys.com>

	* ld/Makefile.am: Add ARC64 targets.
	* ld/configure.tgt: Likewise.
	* ld/Makefile.in: Regenerate.
	* ld/emulparams/arc64elf32.sh: New file.
	* ld/emulparams/arc64elf64.sh: Likewise.
	* ld/emulparams/arc64linux32.sh: Likewise.
	* ld/emulparams/arc64linux64.sh: Likewise.
	* ld/scripttempl/elfarc.sc: Update stack and heap definitions.
	* ld/testsuite/ld-arc/got-weak.d: Deleted file.
	* ld/testsuite/ld-arc/got-weak.s: Likewise.

Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
2023-09-25 10:55:51 +03:00
Claudiu Zissulescu
cd60a3956d arc: Update elfarcv2 script template
Update ARC's elfarcv2 script template with:

- The .ivt section (Interrupt Vector Table) is mapped at the begining
  of STARTUP_MEMORY when ivtbase_addr is not defined. Previously, it
  was pointing to 0x00.

- MEMORY_FILE is a new emulation paramter and sets the name for the
  linker script file which holds the MEMORY commands required by
  arcv2elfx emulation.

- Four new linker variables are introduced available when arcv2elf emulation is used:
  * __TEXT_REGION_ORIGIN__ Once defined it is setting the text region origin. By default it points to zero.
  * __TEXT_REGION_LENGTH__ Once defined it is setting the text region length. By default it is set to 2M.
  * __DATA_REGION_ORIGIN__ Once defined it is setting the data region origin. By default it is set to 0x80000000.
  * __DATA_REGION_LENGTH__ Once defined it is setting the data region length. By default it is set to 2M.

ld/ChangeLog:

	* scripttempl/elfarcv2.sc: Update script template.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2023-08-31 08:13:53 +03:00
Sam James
b5c37946cc Revert "2.41 Release sources"
This reverts commit 675b9d612c.

See https://sourceware.org/pipermail/binutils/2023-August/128761.html.
2023-08-02 12:06:23 +01:00
Nick Clifton
675b9d612c 2.41 Release sources 2023-08-02 09:23:36 +01:00
Alan Modra
63e8fb8625 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.
2023-07-17 08:17:44 +09:30
Alan Modra
9dbd067f96 .noinit and .persistent for msp430
Similar to the previous patch, but also tidy a few more sections.

	* scripttempl/elf32msp430.sc (.text, .rodata, .data, .bss, .noinit),
	(.persistent): Align the section rather than aligning inside.
2023-07-12 09:31:40 +09:30
Alan Modra
dbe6d432d1 .noinit and .persistent alignment
It's more elegant to make the section match up with its "_start"
symbol.  We could align by setting the address of the section (by
using ALIGN before the colon), but this way we also set sh_addralign
to at least $ALIGNMENT.

	* scripttempl/elf.sc (.noinit, .persistent): Align the output
	section rather than using ". = ALIGN();" at the beginning.
	Set address to zero when not a final link.
2023-07-12 09:31:40 +09:30
Alan Modra
9596ca8194 Re: Align linkerscript symbols according to ABI
Align dot before symbols defined outside of output sections.  Before _end
is already aligned.

	* scripttempl/elf.sc (def_symbol): Tidy excess space.
	(_edata): Align before emitting symbol when SYMBOL_ABI_ALIGNMENT.
2023-07-12 09:31:40 +09:30
Andreas Krebbel
a5042543d8 Align linkerscript symbols according to ABI
Apply ABI specific alignment to symbols generated in the default
linker script.
2023-07-05 14:29:03 +02:00
Dimitar Dimitrov
35130e73da ld: pru: Place exception-handling sections correctly
* scripttempl/pru.sc (OUTPUT_SECTION_ALIGN): New helper variable to place at end of DMEM output sections.
  (.data): Use the helper variable.
  (.eh_frame): New output section.
  (.gnu_extab): Ditto.
  (.gcc_except_table): Ditto.
  (.resource_table): Use the helper variable.
2023-05-04 12:41:55 +01:00
Alan Modra
1d7e244fc5 Another source_sh
* scripttempl/z80.sc: Use source_sh to source elf.sc.
2023-03-17 21:10:05 +10:30
Alan Modra
6752dd75f7 Re: Add --enable-linker-verssion
Output sections without any input sections to initialise their flags
have their flags initialised by data statements to LOAD, ALLOC,
HAS_CONTENTS by default.  This is wrong for .comment.  Fix that by
making the script initialise the section type to INFO, one of the
noalloc section types.  That also allows the address of .comment to be
set to zero, as is usual for non-alloc sections.

Also, use source_sh for all of the sourced scripts to set up make
dependencies.

	PR 30187
	* scripttempl/misc-sections.sc: Set .comment address to zero
	and type to INFO.
	* scripttempl/ft32.sc: Fix breakages from last edit.
	* scripttempl/arclinux.sc: Use source_sh to source DWARF.sc
	and misc-sections.sc.
	* scripttempl/avr.sc: Likewise.
	* scripttempl/dlx.sc: Likewise.
	* scripttempl/elf.sc: Likewise.
	* scripttempl/elf32cr16.sc: Likewise.
	* scripttempl/elf32crx.sc: Likewise.
	* scripttempl/elf32msp430.sc: Likewise.
	* scripttempl/elf64bpf.sc: Likewise.
	* scripttempl/elf64hppa.sc: Likewise.
	* scripttempl/elf_chaos.sc: Likewise.
	* scripttempl/elfarc.sc: Likewise.
	* scripttempl/elfarcv2.sc: Likewise.
	* scripttempl/elfd10v.sc: Likewise.
	* scripttempl/elfd30v.sc: Likewise.
	* scripttempl/elfm68hc11.sc: Likewise.
	* scripttempl/elfm68hc12.sc: Likewise.
	* scripttempl/elfm9s12z.sc: Likewise.
	* scripttempl/elfmicroblaze.sc: Likewise.
	* scripttempl/elfxgate.sc: Likewise.
	* scripttempl/elfxtensa.sc: Likewise.
	* scripttempl/epiphany_4x4.sc: Likewise.
	* scripttempl/i386beos.sc: Likewise.
	* scripttempl/i386go32.sc: Likewise.
	* scripttempl/ia64vms.sc: Likewise.
	* scripttempl/ip2k.sc: Likewise.
	* scripttempl/iq2000.sc: Likewise.
	* scripttempl/mep.sc: Likewise.
	* scripttempl/mmo.sc: Likewise.
	* scripttempl/nds32elf.sc: Likewise.
	* scripttempl/pru.sc: Likewise.
	* scripttempl/v850.sc: Likewise.
	* scripttempl/v850_rh850.sc: Likewise.
	* scripttempl/visium.sc: Likewise.
	* scripttempl/xstormy16.sc: Likewise.
	* scripttempl/z80.sc: Likewise.
	* testsuite/ld-scripts/ld-version-2.d: Don't skip ft32 or pru.
2023-03-16 17:30:28 +10:30
Nick Clifton
2d5783fad7 Add --enable-linker-version option to bfd linker to add an entry in the .comment section.
PR 30187
  * NEWS: Mention the new feature. * ld.texi: Document the new feature. * ldgram.y: Handle LINKER_VERSION token. * ldlang.c (lang_add_version): New function. (enable_linker_version): New global variable. * ldlang.h (land_add_version): Prototype. (enable_linker_version): Export. * ldlex.h (OPTION_ENABLE_LINKER_VERSION): Define. (OPTION_DISABLE_LINKER_VERSION): Define. * ldlex.l (LINKER_VERSION): Add token. * lexsup.c (ld_options): Add --enable-linker-version and --disable-linker-version. (parse_args): Handle the new options. * scripttempl/arclinux.sc: Remove stabs and comment sections and replace with inclusion of misc-sections.sc * scripttempl/avr.sc: Likewise. * scripttempl/dlx.sc: Likewise. * scripttempl/elf.sc: Likewise. * scripttempl/elf32cr16.sc: Likewise. * scripttempl/elf32crx.sc: Likewise. * scripttempl/elf32msp430.sc: Likewise. * scripttempl/elf64bpf.sc: Likewise. * scripttempl/elf64hppa.sc: Likewise. * scripttempl/elf_chaos.sc: Likewise. * scripttempl/elfarc.sc: Likewise. * scripttempl/elfarcv2.sc: Likewise. * scripttempl/elfd10v.sc: Likewise. * scripttempl/elfd30v.sc: Likewise. * scripttempl/elfm68hc11.sc: Likewise. * scripttempl/elfm68hc12.sc: Likewise. * scripttempl/elfm9s12z.sc: Likewise. * scripttempl/elfmicroblaze.sc: Likewise. * scripttempl/elfxgate.sc: Likewise. * scripttempl/elfxtensa.sc: Likewise. * scripttempl/epiphany_4x4.sc: Likewise. * scripttempl/ft32.sc: Likewise. * scripttempl/ip2k.sc: Likewise. * scripttempl/iq2000.sc: Likewise. * scripttempl/mep.sc: Likewise. * scripttempl/nds32elf.sc: Likewise. * scripttempl/pru.sc: Likewise. * scripttempl/v850.sc: Likewise. * scripttempl/v850_rh850.sc: Likewise. * scripttempl/visium.sc: Likewise. * scripttempl/xstormy16.sc: Likewise. * scripttempl/z80.sc: Likewise. * testsuite/ld-scripts/script.exp: Run new tests. * scripttempl/misc-sections.sc: New file. * testsuite/ld-scripts/ld-version-2.d: New file. * testsuite/ld-scripts/ld-version.d: New file. * testsuite/ld-scripts/ld-version.t: New file.
2023-03-15 14:27:21 +00:00
Dimitar Dimitrov
ba268471bf ld: pru: Add optional section alignments
The Texas Instruments SoCs with AARCH64 host processors have stricter
alignment requirements than ones with ARM32 host processors.  It's not
only the requirement for resource_table to be aligned to 8.  But also
any loadable segment size must be a multiple of 4 [1].

The current PRU default linker script may output a segment size not
aligned to 4, which would cause firmware load failure on AARCH64 hosts.

Fix this by using COMMONPAGESIZE and MAXPAGESIZE to signify respectively
the section memory size requirement and the resource table section's
start address alignment.  This would avoid penalizing the ARM32 hosts,
for which the default values (1 and 1) are sufficient.

For AARCH64 hosts, the alignments would be overwritten from GCC spec
files using the linker command line, e.g.:
  -z common-page-size=4 -z max-page-size=8

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/remoteproc/pru_rproc.c?h=v6.1#n555

ld/ChangeLog:

	* scripttempl/pru.sc (_data_end): Remove the alignment.
	(.data): Align output section size to COMMONPAGESIZE.
	(.resource_table): Ditto.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2023-02-04 14:12:47 +02:00
Dimitar Dimitrov
a9c9f0650c ld: pru: Merge the bss input sections into data
The popular method to load PRU firmware is through the remoteproc Linux
kernel driver.  In order to save a few bytes from the firmware, the PRU
CRT0 is spared from calling memset for the bss segment [1].  Instead the
host loader is supposed to zero out the bss segment.  This is important
for PRU, which typically has only 8KB for instruction memory.

The legacy non-mainline PRU host driver relied on the default
behaviour of the kernel core remoteproc [2].  That default is to zero
out the loadable memory regions not backed by file storage (i.e. the
bss sections).  This worked for the libgloss' CRT0.

But the PRU loader merged in mainline Linux explicitly changes the
default behaviour [3].  It no longer is zeroing out memory regions.
Hence the bss sections are not initialized - neither by CRT0, nor by the
host loader.

This patch fixes the issue by aligning the GNU LD default linker script
with the mainline Linux kernel expectation.  Since the mainline kernel
driver is submitted by the PRU manufacturer itself (Text Instruments),
we can consider that as defining the ABI.

This change has been tested on Beaglebone AI-64 [4].  Static counter
variables in the firmware are now always starting from zero, as
expected.  There was only one new toolchain test failure in orphan3.d,
due to reordering of the output sections.  I believe this is a harmless
issue.  I could not rewrite the PASS criteria to ignore the output
section ordering, so I have disabled that test case for PRU.

[1] https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=libgloss/pru/crt0.S;h=b3f0d53a93acc372f461007553e7688ca77753c9;hb=HEAD#l40
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/remoteproc/remoteproc_elf_loader.c?h=v6.1#n228
[3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/remoteproc/pru_rproc.c?h=v6.1#n641
[4] https://beagleboard.org/ai-64

ld/ChangeLog:

	* scripttempl/pru.sc (.data): Merge .bss input sections into the
	.data output section.
	* testsuite/ld-elf/orphan3.d: Disable for PRU.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2023-02-04 14:12:13 +02:00
Mark Harmstone
8819b23615 Avoid unaligned pointer reads in PEP .idata section
This is something I discovered when working on aarch64, though it's
relevant to x86_64 too.

The PE32+ imports are located in the .idata section, which starts off
with a 20-byte structure for each DLL, containing offsets into the rest
of the section. This is the Import Directory Table in
https://learn.microsoft.com/en-us/windows/win32/debug/pe-format, which
is a concatenation of the .idata$2 sections. This is then followed by an
20 zero bytes generated by the linker script, which calls this .idata$3.

After this comes the .idata$4 entries for each function, which the
loader overwrites with the function pointers. Because there's no padding
between .idata$3 and .idata$4, this means that if there's an even number
of DLLs, the function pointers won't be aligned on an 8-byte boundary.

Misaligned reads are slower on x86_64, but this is more important on
aarch64, as the e.g. `ldr x0, [x0, :lo12:__imp__func]` the compiler
might generate requires __imp__func (the .idata$4 entry) to be aligned
to 8 bytes. Without this you get IMAGE_REL_ARM64_PAGEOFFSET_12L overflow
errors.
2023-01-04 03:47:09 +00:00
Alan Modra
d87bef3a7b Update year range in copyright notice of binutils files
The newer update-copyright.py fixes file encoding too, removing cr/lf
on binutils/bfdtest2.c and ld/testsuite/ld-cygwin/exe-export.exp, and
embedded cr in binutils/testsuite/binutils-all/ar.exp string match.
2023-01-01 21:50:11 +10:30
Nick Clifton
a7a32d588f Keep the .drectve section when performing a relocateable link.
PR 29900
	* scripttempl/pe.sc: Keep the .drectve section when performing a
	relocateable link.
	* scripttempl/pep.sc: Likewise.
2022-12-21 10:23:08 +00:00
Indu Bhagat
cf0e0a0ba9 bfd: linker: merge .sframe sections
The linker merges all the input .sframe sections.  When merging, the
linker verifies that all the input .sframe sections have the same
abi/arch.

The linker uses libsframe library to perform key actions on the
.sframe sections - decode, read, and create output data.  This
implies buildsystem changes to make and install libsframe before
libbfd.

The linker places the output .sframe section in a new segment of its
own: PT_GNU_SFRAME.  A new segment is not added, however, if the
generated .sframe section is empty.

When a section is discarded from the final link, the corresponding
entries in the .sframe section for those functions are also deleted.

The linker sorts the SFrame FDEs on start address by default and sets
the SFRAME_F_FDE_SORTED flag in the .sframe section.

This patch also adds support for generation of SFrame unwind
information for the .plt* sections on x86_64.  SFrame unwind info is
generated for IBT enabled PLT, lazy/non-lazy PLT.

The existing linker option --no-ld-generated-unwind-info has been
adapted to include the control of whether .sframe unwind information
will be generated for the linker generated sections like PLT.

Changes to the linker script have been made as necessary.

ChangeLog:

	* Makefile.def: Add install dependency on libsframe for libbfd.
	* Makefile.in: Regenerated.
	* bfd/Makefile.am: Add elf-sframe.c
	* bfd/Makefile.in: Regenerated.
	* bfd/bfd-in2.h (SEC_INFO_TYPE_SFRAME): Regenerated.
	* bfd/configure: Regenerate.
	* bfd/configure.ac: Add elf-sframe.lo.
	* bfd/elf-bfd.h (struct sframe_func_bfdinfo): New struct.
	(struct sframe_dec_info): Likewise.
	(struct sframe_enc_info): Likewise.
	(struct elf_link_hash_table): New member for encoded .sframe
	object.
	(struct output_elf_obj_tdata): New member.
	(elf_sframe): New access macro.
	(_bfd_elf_set_section_sframe): New declaration.
	* bfd/elf.c (get_segment_type): Handle new segment
	PT_GNU_SFRAME.
	(bfd_section_from_phdr): Likewise.
	(get_program_header_size): Likewise.
	(_bfd_elf_map_sections_to_segments): Likewise.
	* bfd/elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Add
	contents to the .sframe sections or .plt* entries.
	* bfd/elflink.c (elf_section_ignore_discarded_relocs): Handle
	SEC_INFO_TYPE_SFRAME.
	(_bfd_elf_default_action_discarded): Handle .sframe section.
	(elf_link_input_bfd): Merge .sframe section.
	(bfd_elf_final_link): Write the output .sframe section.
	(bfd_elf_discard_info): Handle discarding .sframe section.
	* bfd/elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Create
	.sframe section for .plt and .plt.sec.
	(_bfd_x86_elf_finish_dynamic_sections): Handle .sframe from
	.plt* sections.
	* bfd/elfxx-x86.h (PLT_SFRAME_FDE_START_OFFSET): New
	definition.
	(SFRAME_PLT0_MAX_NUM_FRES): Likewise.
	(SFRAME_PLTN_MAX_NUM_FRES): Likewise.
	(struct elf_x86_sframe_plt): New structure.
	(struct elf_x86_link_hash_table): New member.
	(struct elf_x86_init_table): New members for .sframe
	creation.
	* bfd/section.c: Add new definition SEC_INFO_TYPE_SFRAME.
	* binutils/readelf.c (get_segment_type): Handle new segment
	PT_GNU_SFRAME.
	* ld/ld.texi: Update documentation for
	--no-ld-generated-unwind-info.
	* ld/scripttempl/elf.sc: Support .sframe sections.
	* ld/Makefile.am (TESTSFRAMELIB): Use it.
	(check-DEJAGNU): Likewise.
	* ld/Makefile.in: Regenerated.
	* ld/configure.ac (TESTSFRAMELIB): Set to the .so or .a like TESTBFDLIB.
	* ld/configure: Regenerated.
	* bfd/elf-sframe.c: New file.

include/ChangeLog:

	* elf/common.h (PT_GNU_SFRAME): New definition.
	* elf/internal.h (struct elf_segment_map): Handle new segment
	type PT_GNU_SFRAME.

ld/testsuite/ChangeLog:

	* ld/testsuite/ld-bootstrap/bootstrap.exp: Add SFRAMELIB.
	* ld/testsuite/ld-aarch64/aarch64-elf.exp: Add new test
	  sframe-simple-1.
	* ld/testsuite/ld-aarch64/sframe-bar.s: New file.
	* ld/testsuite/ld-aarch64/sframe-foo.s: Likewise.
	* ld/testsuite/ld-aarch64/sframe-simple-1.d: Likewise.
	* ld/testsuite/ld-sframe/sframe-empty.d: New test.
	* ld/testsuite/ld-sframe/sframe-empty.s: New file.
	* ld/testsuite/ld-sframe/sframe.exp: New testsuite.
	* ld/testsuite/ld-x86-64/sframe-bar.s: New file.
	* ld/testsuite/ld-x86-64/sframe-foo.s: Likewise.
	* ld/testsuite/ld-x86-64/sframe-simple-1.d: Likewise.
	* ld/testsuite/ld-x86-64/sframe-plt-1.d: Likewise.
	* ld/testsuite/ld-x86-64/sframe-simple-1.d: Likewise.
	* ld/testsuite/ld-x86-64/x86-64.exp: Add new tests -
	  sframe-simple-1, sframe-plt-1.
	* ld/testsuite/lib/ld-lib.exp: Add new proc to check if
	  assembler supports SFrame section.
	* ld/testsuite/ld-sframe/discard.d: New file.
	* ld/testsuite/ld-sframe/discard.ld: Likewise.
	* ld/testsuite/ld-sframe/discard.s: Likewise.
2022-11-15 15:49:47 -08:00
Nick Clifton
fa6895ad35 AVR Linker: Allow the start of the data region to specified on the command line.
PR 29471
	* scripttempl/avr.sc (__DATA_REGION_ORIGIN__): Define.  If a value
	has not been provided on the command line then use DATA_ORIGIN.
	(MEMORY): Use __DATA_REGION_ORIGIN__ as the start of the data region.
2022-11-03 09:17:41 +00:00
Jan Beulich
ddd7bf3e28 drop XC16x bits
Commit 04f096fb9e ("Move the xc16x target to the obsolete list") moved
the architecture from the "obsolete but still available" to the
"obsolete / support removed" list in config.bfd, making the architecture
impossible to enable (except maybe via "enable everything" options").

Note that I didn't touch */po/*.po{,t} on the assumption that these
would be updated by some (half)automatic means.
2022-06-27 11:11:46 +02:00
Alan Modra
34c95e6aad Correct .relr.dyn nocombreloc script
* scripttempl/elf.sc (.relr.dyn): Don't depend on $COMBRELOC.
2022-01-13 16:39:35 +10:30
H.J. Lu
6a91be8666 ld: Initial DT_RELR support
Add a -z pack-relative-relocs option to enable DT_RELR and create a
relr.dyn section for DT_RELR.  DT_RELR is implemented with the linker
relaxation infrastructure, but it doesn't require the --relax option
enabled.  -z pack-relative-relocs implies -z combreloc.  -z nocombreloc
implies -z nopack-relative-relocs.

-z pack-relative-relocs is chosen over the similar option in lld,
--pack-dyn-relocs=relr, to implement a glibc binary lockout mechanism
with a special glibc version symbol, to avoid random crashes of DT_RELR
binaries with the existing glibc binaries.

bfd/

	* elf-bfd.h (elf_link_hash_table): Add srelrdyn.
	* elflink.c (_bfd_elf_link_create_dynamic_sections): Create a
	.relr.dyn section for DT_RELR.

include/

	* bfdlink.h (bfd_link_info): Add enable_dt_relr.

ld/

	* News: Mention -z pack-relative-relocs and
	-z nopack-relative-relocs.
	* ld.texi: Document -z pack-relative-relocs and
	-z nopack-relative-relocs.
	* ldelf.c (ldelf_after_parse): Disable DT_RELR if not building
	PIE nor shared library.  Add 3 spare dynamic tags for DT_RELR,
	DT_RELRSZ and DT_RELRENT.
	* ldlang.c (lang_relax_sections): Also enable relaxation if
	DT_RELR is enabled.
	* emulparams/elf32_x86_64.sh: Source dt-relr.sh.
	* emulparams/elf_i386.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.
	* emulparams/dt-relr.sh: New file.
	* scripttempl/elf.sc: Support .relr.dyn.
2022-01-12 06:04:29 -08:00
Alan Modra
a2c5833233 Update year range in copyright notice of binutils files
The result of running etc/update-copyright.py --this-year, fixing all
the files whose mode is changed by the script, plus a build with
--enable-maintainer-mode --enable-cgen-maint=yes, then checking
out */po/*.pot which we don't update frequently.

The copy of cgen was with commit d1dd5fcc38ead reverted as that commit
breaks building of bfp opcodes files.
2022-01-02 12:04:28 +10:30
Nick Clifton
44b357eb9a ld: pru: Add pru_irq_map output section
* scripttempl/pru.sc (.pru_irq_map): Define output section.
	* testsuite/ld-pru/pru_irq_map-1.d: New test.
	* testsuite/ld-pru/pru_irq_map-2.d: New test.
	* testsuite/ld-pru/pru_irq_map.s: New test.
2021-11-30 13:11:57 +00:00
Mike Frysinger
5fd82aa264 ld: fix POSIX shell test usage
POSIX test uses = for compares, not == which is a bashism.
2021-11-25 22:59:44 -05:00
Dimitar Dimitrov
5109a7bd9b ld: pru: Fix resource_table output section alignment
My commit 261980de18 added alignment for the resource table symbol.
But it is wrong.  The Linux remoteproc driver loads and interprets the
contents of the .resource_table ELF section, not of a table symbol.

Without this patch, if the linker happens to output padding for symbol
alignment, then the resource table contents as viewed by the kernel
loader would "shift" and look corrupted.

ld/ChangeLog:

	* scripttempl/pru.sc  (.resource_table): Align the output
	section, not the first symbol.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2021-09-30 22:15:50 +03:00
Dimitar Dimitrov
261980de18 PRU: Add alignment for resource table, and allow sizes of memory regions to be set from the command line.
ld	* scripttempl/pru.sc (.resource_table): Add ALIGN directive.
	Use symbols for memory sizes.
2021-05-10 13:58:17 +01:00
Clément Chigot
1b2cb8e2ee aix: implement TLS relocation for gas and ld
Add support for TLS in XCOFF. Amongst the things done by this commit:
 - Update XCOFF auxialiary header to match new version and allow TLS
   sections.
 - Add TLS sections (.tdata and .tbss) support in gas and ld.
 - Add support for the TLS relocations in gas and ld.
   Two different types BFD_RELOC are created for PPC and PPC64 as
   the size is a pointer, thus distinct in 32 or 64bit.

The addresses given by ld to .tdata and .tbss is a bit special. In
XCOFF, these addresses are actually offsets from the TLS pointer
computed at runtime. AIX assembly and linker does the same. In
top of that, the .tdata must be before .data (this is mandatory for AIX
loader). Thus, the aix ld script is recomputing "." before .data to restore
its original value. There might be a simpler way, but this one is working.

Optimisation linked to TLS relocations aren't yet implemented.

bfd/
	* reloc.c (BFD_RELOC_PPC_TLS_LE, BFD_RELOC_PPC_TLS_IE,
	BFD_RELOC_PPC_TLS_M, BFD_RELOC_PPC_TLS_ML, BFD_RELOC_PPC64_TLS_GD,
	BFD_RELOC_PPC64_TLS_LD, BFD_RELOC_PPC64_TLS_LE,
	BFD_RELOC_PPC64_TLS_IE, BFD_RELOC_PPC64_TLS_M,
	BFD_RELOC_PPC64_TLS_ML): New relocations.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* coff-rs6000.c (xcoff_calculate_relocation): Call
	xcoff_reloc_type_tls for TLS relocations.
	(xcoff_howto_table): Implement TLS relocations.
	(_bfd_xcoff_reloc_type_lookup): Add cases TLS relocations.
	(xcoff_reloc_type_tls): New function.
	* coff64-rs6000.c (xcoff_calculate_relocation): Likewise.
	(xcoff_howto_table): Likewise.
	(_bfd_xcoff_reloc_type_lookup): Likewise.
	* coffcode.h (sec_to_styp_flags): Handle TLS sections.
	(styp_to_sec_flags): Likewise.
	(coff_compute_section_file_positions): Avoid file offset
	optimisation for .data when the previous section is .tdata.
	(coff_write_object_contents): Handle TLS sections.
	* coffswap.h (coff_swap_aouthdr_out): Add support for
	new fields in aouthdr.
	* libxcoff.h (xcoff_reloc_type_tls): Add prototype.
	* xcofflink.c (xcoff_link_add_symbols): Handle XMC_UL.
	(xcoff_need_ldrel_p): Add cases for TLS relocations.
	(xcoff_create_ldrel): Add l_symndx for TLS sections.
gas/
	* config/tc-ppc.c (ppc_xcoff_text_section, ppc_xcoff_data_section,
	(ppc_xcoff_bss_section, ppc_xcoff_tdata_section,
	(ppc_xcoff_tbss_section): New variables.
	(ppc_text_subsegment, ppc_text_csects, ppc_data_subgments,
	(ppc_data_csects): Removed.
	(ppc_xcoff_section_is_initialized, ppc_init_xcoff_section,
	ppc_xcoff_parse_cons): New functions.
	(md_being): Initialize XCOFF sections.
	(ppc_xcoff_suffix): Add support for TLS relocations
	(fixup_size, md_apply_fix): Add support for new BFD_RELOC.
	(ppc_change_csect): Handle XMC_TL, XMC_UL.  Correctly, add XMC_BS
	to .bss section.  Handle new XCOFF section variables.
	(ppc_comm): Likewise.
	(ppc_toc): Likewise.
	(ppc_symbol_new_hook): Likewise.
	(ppc_frob_symbol): Likewise.
	(ppc_fix_adjustable): Add tbss support.
	* config/tc-ppc.h (TC_PARSE_CONS_EXPRESSION): New define.
	(ppc_xcoff_parse_cons): Add prototype.
	(struct ppc_xcoff_section): New structure.
ld/
	* emultempl/aix.em: Ensure .tdata section is removed
	if empty, even with -r flag.
	* scripttempl/aix.sc: Handle TLS sections.
	* testsuite/ld-powerpc/aix52.exp: Add new tests.
	* testsuite/ld-powerpc/aix-tls-reloc-32.d: New test.
	* testsuite/ld-powerpc/aix-tls-reloc-64.d: New test.
	* testsuite/ld-powerpc/aix-tls-reloc.ex: New test.
	* testsuite/ld-powerpc/aix-tls-reloc.s: New test.
	* testsuite/ld-powerpc/aix-tls-section-32.d: New test.
	* testsuite/ld-powerpc/aix-tls-section-64.d: New test.
	* testsuite/ld-powerpc/aix-tls-section.ex: New test.
	* testsuite/ld-powerpc/aix-tls-section.s: New test.
include/
	* coff/internal.h (struct internal_aouthdr): Add new fields.
	* coff/rs6000.h (AOUTHDRÃ): Add new fields.
	* coff/rs6k64.h (struct external_filehdr): Likewise.
	* coff/xcoff.h (_TDATA), _TBSS): New defines
	(RS6K_AOUTHDR_TLS_LE, RS6K_AOUTHDR_RAS, RS6K_AOUTHDR_ALGNTDATA,
	RS6K_AOUTHDR_SHR_SYMTAB, RS6K_AOUTHDR_FORK_POLICY,
	RS6K_AOUTHDR_FORK_COR): New defines.
	(XMC_TU): Removed.
	(XMC_UL): New define.
2021-03-12 22:47:33 +10:30
Clément Chigot
4a403be0c1 aix: implement R_TOCU and R_TOCL relocations
Implement support for largetoc on XCOFF.
R_TOCU and R_TOCL are referenced by the new BFD defines:
BFD_RELOC_PPC_TOC16_HI and BFD_RELOC_PPC_TOC16_LO.
A new toc storage class is added XMC_TE.

In order to correctly handle R_TOCU, the logic behind
xcoff_reloc_type_toc is changed to compute the whole TOC offset
instead of just the difference between the "link" offset and the
"assembly" offset.

In gas, add a function to transform addis format used by AIX
"addis RT, D(RA)" into the ELF format "addis RT, RA, SI".

bfd/
	* reloc.c (BFD_RELOC_PPC_TOC16_HI, BFD_RELOC_PPC_TOC16_LO):
	New relocations.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
	* coff-rs6000.c (xcoff_calculate_relocation): Call
	xcoff_reloc_type_toc for R_TOCU and R_TOCL.
	(xcoff_howto_table): Remove src_mask for TOC relocations.
	Add R_TOCU and R_TOCL howtos.
	(_bfd_xcoff_reloc_type_lookup): Add cases for
	BFD_RELOC_PPC_TOC16_HI and BFD_RELOC_PPC_TOC16_LO.
	(xcoff_reloc_type_toc): Compute the whole offset.
	Implement R_TOCU and R_TOCL.
	* coff64-rs6000.c (xcoff64_calculate_relocation):
	Likewise.
	(xcoff64_howto_table): Likewise.
	(xcoff64_reloc_type_lookup): Likewise.
gas/
	* config/tc-ppc.c (ppc_xcoff_suffix): New function.
	(MAP, MAP32, MAP64): New macros for XCOFF.
	(ppc_xcoff_fixup_addis): New function.
	(ppc_is_toc_sym): Handle XMC_TE.
	(fixup_size): Add cases for BFD_RELOC_PPC_TOC16_HI and
	BFD_RELOC_PPC_TOC16_LO.
	(md_assemble): Call ppc_xcoff_fixup_addis for XCOFF.
	(ppc_change_csect): Handle XMC_TE.
	(ppc_tc): Enable .tc symbols to have only a XMC_TC or XMC_TE
	storage class.
	(ppc_symbol_new_hook): Handle XMC_TE.
	(ppc_frob_symbol): Likewise.
	(ppc_fix_adjustable): Likewise.
	(md_apply_fix): Handle BFD_RELOC_PPC_TOC16_HI and
	BFD_RELOC_PPC_TOC16_LO.
ld/
	* scripttempl/aix.sc: Add .te to .data section.
	* testsuite/ld-powerpc/aix52.exp: Add test structure for AIX7+.
	Add aix-largetoc-1 test.
	* testsuite/ld-powerpc/aix-largetoc-1-32.d: New test.
	* testsuite/ld-powerpc/aix-largetoc-1-64.d: New test.
	* testsuite/ld-powerpc/aix-largetoc-1.ex: New test.
	* testsuite/ld-powerpc/aix-largetoc-1.s: New test.
2021-03-12 22:47:23 +10:30
Jan Beulich
67b0f68480 bfd: strip symbols not representable in COFF/PE symbol table
The offset-within-section field in the symbol table entry is only 32
bits wide, so rather than emitting bogus entries omit them, and issue
a diagnostic identifying the issue.

This requires adjusting the PR/22267 test to no longer produce symbols
with out of range values on 64-bit BFD. This also depends on
adjustments to testsuite/ld-scripts/map-address.* made by an earlier
patch. The purpose of the test can very well be achieved nevertheless.
2021-03-10 08:12:37 +01:00
Nick Clifton
ba6eb62ff0 Add DWARF-5 section names to PE and PEP linker scripts.
PR 27268
	* scripttempl/pe.sc: Add DWARF-5 section names.
	* scripttempl/pep.sc: Likewise.
2021-03-01 16:25:06 +00:00
Alan Modra
a57d17732e Remove arm-symbianelf
* configure.ac: Delete arm*-*-symbianelf* entry.
	* configure: Regenerate.
bfd/
	* config.bfd (arm*-*-symbianelf*): Move from obsolete to removed.
	* configure.ac: Delete symbian entries.
	* elf-bfd.h (enum elf_target_os): Delete is_symbian.
	* elf32-arm.c: Remove symbian support.  Formatting.
	* targets.c: Delete symbian entries.
	* configure: Regenerate.
binutils/
	* testsuite/lib/binutils-common.exp (supports_gnu_osabi): Remove
	symbianelf.
gas/
	* Makefile.am (TARG_ENV_HFILES): Remove config/te-symbian.h.
	* config/tc-arm.c (elf32_arm_target_format): Remove TE_SYMBIAN
	support.
	* config/te-symbian.h: Delete.
	* configure.tgt: Remove arm-*-symbianelf*.
	* testsuite/gas/arm/arch4t-eabi.d: Don't mention symbianelf in
	target selection.
	* testsuite/gas/arm/arch4t.d: Likewise.
	* testsuite/gas/arm/got_prel.d: Likewise.
	* testsuite/gas/arm/mapdir.d: Likewise.
	* testsuite/gas/arm/mapmisc.d: Likewise.
	* testsuite/gas/arm/mapsecs.d: Likewise.
	* testsuite/gas/arm/mapshort-eabi.d: Likewise.
	* testsuite/gas/arm/thumb-eabi.d: Likewise.
	* testsuite/gas/arm/thumb.d: Likewise.
	* testsuite/gas/arm/thumbrel.d: Likewise.
	* Makefile.in: Regenerate.
	* po/POTFILES.in: Regenerate.
ld/
	* Makefile.am (ALL_EMULATION_SOURCES): Remove earmsymbian.c.
	Don't include symbian dep file.
	* configure.tgt: Remove arm*-*-symbianelf* entry.
	* emulparams/armsymbian.sh: Delete.
	* ld.texi: Don't mention symbian.
	* scripttempl/armbpabi.sc: Delete.
	* testsuite/ld-arm/symbian-seg1.d: Delete.
	* testsuite/ld-arm/symbian-seg1.s: Delete.
	* testsuite/ld-arm/arm-elf.exp: Don't run symbian-seg1.
	* Makefile.in: Regenerate.
	* po/BLD-POTFILES.in: Regenerate.
2021-02-09 23:36:16 +10:30
Alan Modra
1c9c9b9b55 PR27226, ld.bfd contains huge .rodata section
This makes it possible to build ld without any compiled-in scripts,
by setting COMPILE_IN=no in the environment.  pe, beos and pdp11
targets didn't support scripts from the file system, with pdp11
nastily editing the ld/ldscripts file so that the built-in script
didn't match.

	PR 27226
	* emulparams/alphavms.sh: Don't set COMPILE_IN.
	* emulparams/elf64_ia64_vms.sh: Likewise.
	* emulparams/elf64mmix.sh: Likewise.
	* emulparams/elf_iamcu.sh: Likewise.
	* emulparams/elf_k1om.sh: Likewise.
	* emulparams/elf_l1om.sh: Likewise.
	* emulparams/mmo.sh: Likewise.
	* emulparams/pdp11.sh: Set DATA_SEG_ADDR.
	* scripttempl/pdp11.sc: Use it.
	* emultempl/pdp11.em: Don't edit .xn script for separate_code,
	instead use .xe script.  Support scripts from file system.
	* emultempl/beos.em: Support scripts from file system.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* testsuite/ld-bootstrap/bootstrap.exp: Make tmpdir/ldscripts link.
2021-01-26 20:54:43 +10:30
Fangrui Song
9e42b97628 Add some more DWARF-5 sections 2021-01-25 11:35:57 +00:00
Nick Clifton
b8df69003d Update linker scripts with the names of new DWARF-5 debug sections.
* scripttempl/DWARF.sc: Add .debug_loclists, .debug_rnglists,
	.debug_line_str and .debug_str_offsets.  Move .debug_macro and
	.debug_addr into DWARF-5 section.
2021-01-25 11:20:20 +00:00
Alan Modra
250d07de5c Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
H.J. Lu
3ed3c10425 arc: Enable -Ttext-segment
Define TEXT_START_ADDR and SHLIB_TEXT_START_ADDR with SEGMENT_START to
enable -Ttext-segment.

	PR ld/26970
	* scripttempl/elfarc.sc (TEXT_START_ADDR): New.  Add SEGMENT_START.
	(SHLIB_TEXT_START_ADDR): Likewise.
2020-12-01 04:27:41 -08:00
Jozef Lawrynowicz
2c6f3e56cb ELF: Support .noinit and .persistent sections
The ".persistent" section is for data that should be initialized during
load, but not during application reset.

The ".noinit" section is for data that should not be initialized during
load or application reset.

Targets utilizing the elf.sc linker script template can define
HAVE_{NOINIT,PERSISTENT}=yes to include the .noinit or .persistent
output sections in the generated linker script.

Targets with existing support for .noinit did not handle unique
.noinit.* and .gnu.linkonce.n.* sections the .noinit output section,
this patch also fixes that.

bfd/ChangeLog:

	* elf.c (special_sections_g): Add .gnu.linkonce.n and .gnu.linkonce.p.
	(special_sections_n): Add .noinit.
	(special_sections_p): Add .persistent.

binutils/ChangeLog:

	* testsuite/lib/binutils-common.exp (supports_noinit_section): New.
	(supports_persistent_section): New.

gas/ChangeLog:

	* testsuite/gas/elf/elf.exp: Run new tests.
	* testsuite/gas/elf/section25.d: New test.
	* testsuite/gas/elf/section25.s: New test.
	* testsuite/gas/elf/section26.d: New test.
	* testsuite/gas/elf/section26.s: New test.

ld/ChangeLog:

	* emulparams/armelf.sh (OTHER_SECTIONS): Remove .noinit section
	definition.
	Define HAVE_{NOINIT,PERSISTENT}=yes.
	* scripttempl/avr.sc (.noinit): Add .noinit.* and .gnu.linkonce.n.*
	input section wildcard patterns.
	* scripttempl/elf.sc: Define .noinit and .persistent sections when
	HAVE_NOINIT or HAVE_PERSISTENT are defined to "yes".
	* scripttempl/elf32msp430.sc (.noinit): Add .noinit.* and
	.gnu.linkonce.n.*. input section wildcard patterns.
	(.persistent): Add .persistent.* and
	.gnu.linkonce.p.*. input section wildcard patterns.
	* scripttempl/elfarcv2.sc (.noinit): Add .noinit.* and
	.gnu.linkonce.n.*. input section wildcard patterns.
	* scripttempl/pru.sc: Likewise.
	* testsuite/ld-elf/noinit-sections-1.d: New test.
	* testsuite/ld-elf/noinit-sections-2.d: New test.
	* testsuite/ld-elf/noinit-sections-2.l: New test.
	* testsuite/ld-elf/noinit-sections.s: New test.
	* testsuite/ld-elf/persistent-sections-1.d: New test.
	* testsuite/ld-elf/persistent-sections-2.d: New test.
	* testsuite/ld-elf/persistent-sections-2.l: New test.
	* testsuite/ld-elf/persistent-sections.s: New test.
2020-11-27 10:45:35 +00:00
Jozef Lawrynowicz
64b63c2993 MSP430: Fix alignment of __*_array_start symbols in default linker script
__{preinit,init,fini}_array_start symbols must be word aligned in
linker scripts. If the section preceding the __*_array_start symbol
has an odd size, then a NULL byte will be present between the start
symbol and the .*_array section itself, when the section gets
automatically word-aligned.

This results in a branch to an invalid address when the CRT startup
code tries to run through the functions listed in the array sections.

Some MSP430 linker scripts do not align the __*_array start symbols, so
this added warning will catch that problem and help the user avoid
the potential incorrect execution of the program.

ld/ChangeLog:

	* emultempl/msp430.em (input_section_exists): New.
	(check_array_section_alignment): New.
	(gld${EMULATION_NAME}_finish): New.
	* scripttempl/elf32msp430.sc: Add ALIGN directives before the
	definition of __*_array_start symbols.
	* testsuite/ld-msp430-elf/finiarray-warn.ld: New test.
	* testsuite/ld-msp430-elf/finiarray-warn.r: New test.
	* testsuite/ld-msp430-elf/initarray-nowarn.ld: New test.
	* testsuite/ld-msp430-elf/initarray-warn.ld: New test.
	* testsuite/ld-msp430-elf/initarray-warn.r: New test.
	* testsuite/ld-msp430-elf/initarray.s: New test.
	* testsuite/ld-msp430-elf/msp430-elf.exp: Run new tests.
	* testsuite/ld-msp430-elf/preinitarray-warn.ld: New test.
	* testsuite/ld-msp430-elf/preinitarray-warn.r: New test.
2020-08-28 14:01:10 +01:00
Shahab Vahedi
223d5266de ARC: Fix ld/pr24511 test
With this patch, ld/pr24511 test passes for ARC.

At first glance, the test was failing because the order of
"__init_array_start" and "__fini_array_start" weak symbols were
reversed:

$ nm -n dump.out

      expected output          |          real output
00002104 D __init_array_start  |  00002104 D __fini_array_start
0000210c D __fini_array_start  |  00002104 D __init_array_start

The order of the symbols are different as a side effect of both
symbols being mapped to the _same_ address (0x2104).  Looking
further into the mapping logs [1] revealed that the linker
script must consider all instances of ".init_array" (in other
words ".init_array.*") inside its relevant section. Same logic
holds for ".fini_array".

Therefore, adding "KEEP (*(SORT(.init_array.*)))" to the linker
script, along with the one for ".finit_array.*", resolved the
problem.  While at it, I took the liberty of refactoring the
script a little bit and made those pieces of script macros.

[1] Linker's mapping for the relevant part of the test
---------------------------------------------------------------
.init_array     0x2104        0x0
                0x2104        PROVIDE (__init_array_start = .)
 *(.init_array)
                [!provide]    PROVIDE (__init_array_end = .)

.fini_array     0x2104        0x0
                0x2104        PROVIDE (__fini_array_start = .)
 *(.fini_array)
                [!provide]    PROVIDE (__fini_array_end = .)

.data           0x2104        0x0
 *(.data .data.* .gnu.linkonce.d.*)
 .data          0x2104        0x0 pr24511.o

.init_array.01000
                0x2104        0x8
 .init_array.01000
                0x2104        0x8 pr24511.o

.fini_array.01000
                0x210c        0x8
 .fini_array.01000
                0x210c        0x8 pr24511.o
---------------------------------------------------------------

ld:
	* scripttempl/elfarc.sc (.init_array): Keep ".init_array.*".
	  (.fini_array): Keep ".fini_array.*".

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2020-07-31 12:15:17 +03:00