[Bug ld/29649] New: ld: Insufficient checking that BFD backend is suitable for ld emulation on aarch64

2022-10-03 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=29649

Bug ID: 29649
   Summary: ld: Insufficient checking that BFD backend is suitable
for ld emulation on aarch64
   Product: binutils
   Version: 2.40 (HEAD)
Status: NEW
  Severity: normal
  Priority: P2
 Component: ld
  Assignee: unassigned at sourceware dot org
  Reporter: acoplan at gcc dot gnu.org
  Target Milestone: ---

Configuring with --target=aarch64-none-elf --enable-targets=all --disable-gdb,
I see:

$ cat t.s
.global _start
_start:
nop
$ gas/as-new t.s -o t.o
$ ld/ld-new t.o --oformat pei-aarch64-little
ld/ld-new: BFD (GNU Binutils) 2.39.50.20221003 assertion fail
elfnn-aarch64.c:4829

The assertion failing here is:

BFD_ASSERT (is_aarch64_elf (output_bfd));

the problem is we call the AArch64 ELF backend function
bfd_elfNN_aarch64_set_options from the emulation hook
aarch64_elf_create_output_section_statements, but the actual BFD backend in use
for the output BFD is the pei-aarch64-little backend.

I think we need to be stricter about ensuring we only allow valid combinations
of BFD backend and ld emulation. If we instead set the BFD backend to
mach-o-arm64, we reject it with this error:

$ ld/ld-new t.o --oformat mach-o-arm64
ld/ld-new: error: cannot change output format whilst linking AArch64 binaries

but it seems this is only by accident, since the check that handles this is
looking specifically for the string "aarch64" in the BFD target, but this
target uses "arm64" instead. The check in ld/emultempl/aarch64elf.em is:

/* This is a convenient point to tell BFD about target specific flags.
   After the output has been created, but before inputs are read.  */
static void
aarch64_elf_create_output_section_statements (void)
{
  if (strstr (bfd_get_target (link_info.output_bfd), "aarch64") == NULL)
{
  /* The arm backend needs special fields in the output hash structure.
 These will only be created if the output format is an arm format,
 hence we do not support linking and changing output formats at the
 same time.  Use a link followed by objcopy to change output formats. 
*/
  einfo (_("%F%P: error: cannot change output format "
   "whilst linking %s binaries\n"), "AArch64");
  return;
}

Overall it seems we need to tidy up how non-ELF object formats are handled on
AArch64 (specifically the relationship between ld emulations and BFD backends).

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug ld/30155] New: ld: Segfault in _bfd_nearby_section with custom linker scripts

2023-02-22 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=30155

Bug ID: 30155
   Summary: ld: Segfault in _bfd_nearby_section with custom linker
scripts
   Product: binutils
   Version: 2.41 (HEAD)
Status: NEW
  Severity: normal
  Priority: P2
 Component: ld
  Assignee: unassigned at sourceware dot org
  Reporter: acoplan at gcc dot gnu.org
  Target Milestone: ---

The following fails:

$ cat t1.ld
SECTIONS {
   a : {
 b = .;
  }
}
INSERT BEFORE .text.start
$ cat t2.ld
SECTIONS {
  a = .;
  .text.start 0 : { c = .; }
}
$ echo nop | aarch64-none-elf-as -o t.o
$ aarch64-none-elf-ld --version
GNU ld (GNU Binutils) 2.40.50.20230222
Copyright (C) 2023 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
$ aarch64-none-elf-ld t.o -T t1.ld -T t2.ld
Segmentation fault (core dumped)

Looking in GDB the backtrace is as follows:

(gdb) r
Starting program: /data_sdb/toolchain/bu/dbg-aarch64/bin/aarch64-none-elf-ld
t.o -T t1.ld -T t2.ld

Program received signal SIGSEGV, Segmentation fault.
0x555e33a8 in _bfd_nearby_section (obfd=0x559fa4c0,
s=0x559eed90 <_bfd_std_section+560>, addr=0) at
/home/alecop01/toolchain/src/binutils-gdb/bfd/linker.c:2986
2986next = s->owner->sections;
(gdb) bt
#0  0x555e33a8 in _bfd_nearby_section (obfd=0x559fa4c0,
s=0x559eed90 <_bfd_std_section+560>, addr=0) at
/home/alecop01/toolchain/src/binutils-gdb/bfd/linker.c:2986
#1  0x555e35fa in fix_syms (h=0x55a067e0, data=0x559fa4c0) at
/home/alecop01/toolchain/src/binutils-gdb/bfd/linker.c:3056
#2  0x555df598 in bfd_link_hash_traverse (htab=0x559fc850,
func=0x555e3522 , info=0x559fa4c0) at
/home/alecop01/toolchain/src/binutils-gdb/bfd/linker.c:671
#3  0x555e3657 in _bfd_fix_excluded_sec_syms (obfd=0x559fa4c0,
info=0x559f3980 ) at
/home/alecop01/toolchain/src/binutils-gdb/bfd/linker.c:3068
#4  0x555b48f9 in finish_default () at
/home/alecop01/toolchain/src/binutils-gdb/ld/ldemul.c:303
#5  0x555bcad5 in gldaarch64elf_finish () at eaarch64elf.c:325
#6  0x555b43db in ldemul_finish () at
/home/alecop01/toolchain/src/binutils-gdb/ld/ldemul.c:108
#7  0x555a8909 in lang_process () at
/home/alecop01/toolchain/src/binutils-gdb/ld/ldlang.c:8206
#8  0x555ad42c in main (argc=6, argv=0x7fffbe68) at
/home/alecop01/toolchain/src/binutils-gdb/ld/ldmain.c:501

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug ld/30155] ld: Segfault in _bfd_nearby_section with custom linker scripts

2023-02-22 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=30155

--- Comment #1 from Alex Coplan  ---
This is reproducible on both x86_64 and aarch64 targets, FWIW.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug ld/30155] ld: Segfault in _bfd_nearby_section with custom linker scripts

2023-02-24 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=30155

--- Comment #5 from Alex Coplan  ---
Hi Alan, thanks for working on this. Would it be possible to backport the fix
to any earlier binutils versions (after some time on trunk)?

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug ld/30076] aarch64: stubs can add indirect branch that breaks BTI

2023-03-20 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=30076

Alex Coplan  changed:

   What|Removed |Added

 CC||acoplan at gcc dot gnu.org

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug gas/26395] binutils 2.28 Assertion failure in md_apply_fix at ../../gas/config/tc-aarch64.c:7766.

2020-09-07 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=26395

Alex Coplan  changed:

   What|Removed |Added

Version|2.28|2.36 (HEAD)
 Resolution|OBSOLETE|---
   Last reconfirmed||2020-09-07
 Ever confirmed|0   |1
 Status|RESOLVED|REOPENED
 CC||acoplan at gcc dot gnu.org

--- Comment #7 from Alex Coplan  ---
Reproduced on trunk. The attached assembly can be reduced to the following
single instruction which causes an assertion failure:

$ echo "add x3,x3,:lo12:4" | aarch64-none-elf-as

{standard input}: Assembler messages:
{standard input}: Internal error in md_apply_fix at
gas/config/tc-aarch64.c:8248.
Please report this bug.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug gas/26699] Failure to assemble aarch64 "isb sy" in LP64 Big Endian host environment

2020-10-06 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=26699

Alex Coplan  changed:

   What|Removed |Added

   Last reconfirmed||2020-10-06
 CC||acoplan at gcc dot gnu.org
 Status|UNCONFIRMED |ASSIGNED
   Assignee|unassigned at sourceware dot org   |acoplan at gcc dot 
gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Alex Coplan  ---
Confirmed, I'll take a look.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug gas/26699] Failure to assemble aarch64 "isb sy" in LP64 Big Endian host environment

2020-10-06 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=26699

--- Comment #2 from Alex Coplan  ---
Fixed on master:
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=05cfb0d8cc9b7f8676f5ae55a93642f091d5405f

Will backport to 2.35 after testing.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug gas/26699] Failure to assemble aarch64 "isb sy" in LP64 Big Endian host environment

2020-10-06 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=26699

Alex Coplan  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #4 from Alex Coplan  ---
Fixed on master and binutils 2.35.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug gas/27217] aarch64 as Internal error in md_apply_fix at ....../gas/config/tc-aarch64.c:8330.

2021-03-12 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=27217

Alex Coplan  changed:

   What|Removed |Added

 CC||acoplan at gcc dot gnu.org
 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |DUPLICATE

--- Comment #1 from Alex Coplan  ---
Dup.

*** This bug has been marked as a duplicate of bug 26395 ***

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug gas/26395] binutils 2.28 Assertion failure in md_apply_fix at ../../gas/config/tc-aarch64.c:7766.

2021-03-12 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=26395

Alex Coplan  changed:

   What|Removed |Added

 CC||joel.sherrill at oarcorp dot 
com

--- Comment #8 from Alex Coplan  ---
*** Bug 27217 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug gas/27723] New: aarch64 GAS: Internal error in select_cie_for_fde

2021-04-13 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=27723

Bug ID: 27723
   Summary: aarch64 GAS: Internal error in select_cie_for_fde
   Product: binutils
   Version: 2.37 (HEAD)
Status: NEW
  Severity: normal
  Priority: P2
 Component: gas
  Assignee: unassigned at sourceware dot org
  Reporter: acoplan at gcc dot gnu.org
  Target Milestone: ---

The following fails:

$ cat asm.s
.cfi_startproc
.cfi_window_save
.cfi_endproc
.cfi_startproc
.cfi_window_save
.cfi_endproc
$ bin/aarch64-elf-as asm.s
asm.s: Assembler messages:
asm.s: Internal error in select_cie_for_fde at
/home/alecop01/toolchain/src/binutils-gdb/gas/dw2gencfi.c:2136.
Please report this bug.

The input assembly is reduced from code generated by GCC.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug gas/27723] aarch64 GAS: Internal error in select_cie_for_fde

2021-04-13 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=27723

Alex Coplan  changed:

   What|Removed |Added

 Target||aarch64-*-*

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug gas/27723] Internal error in select_cie_for_fde

2021-04-13 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=27723

--- Comment #2 from Alex Coplan  ---
The fix works fine for the original (unreduced) input, FWIW. Thanks!

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug ld/28393] New: aarch64 ld: assertion fail at elfnn-aarch64.c:5084 with weak undef tlsdesc symbol

2021-09-28 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=28393

Bug ID: 28393
   Summary: aarch64 ld: assertion fail at elfnn-aarch64.c:5084
with weak undef tlsdesc symbol
   Product: binutils
   Version: 2.38 (HEAD)
Status: NEW
  Severity: normal
  Priority: P2
 Component: ld
  Assignee: unassigned at sourceware dot org
  Reporter: acoplan at gcc dot gnu.org
  Target Milestone: ---

The following assembly causes the linker to hit an assertion failure and then
segfault:

$ cat t.s
.global _start
.weak   x
_start:
adrpx0, :tlsdesc:x
$ gas/as-new t.s -o t.o
$ ld/ld-new t.o
ld/ld-new: BFD (GNU Binutils) 2.37.50.20210928 assertion fail
elfnn-aarch64.c:5084
Segmentation fault (core dumped)

The backtrace is:

(gdb) bt
#0  bfd_assert (file=0x5584a3cb "elfnn-aarch64.c", line=5084) at
/home/alecop01/toolchain/src/binutils-gdb/bfd/bfd.c:1649
#1  0x5566 in dtpoff_base (info=0x55aa9040 ) at
elfnn-aarch64.c:5084
#2  0x55604cf6 in elf64_aarch64_relocate_section
(output_bfd=0x55ac14b0, info=0x55aa9040 ,
input_bfd=0x55addd10, input_section=0x55ae0258, contents=0x55ad97a0
"\200", relocs=0x55ae16e0, local_syms=0x55ad9810,
local_sections=0x55adfcd0) at elfnn-aarch64.c:7064
#3  0x5564c5ef in elf_link_input_bfd (flinfo=0x7fffd700,
input_bfd=0x55addd10) at
/home/alecop01/toolchain/src/binutils-gdb/bfd/elflink.c:11427
#4  0x5564f745 in bfd_elf_final_link (abfd=0x55ac14b0,
info=0x55aa9040 ) at
/home/alecop01/toolchain/src/binutils-gdb/bfd/elflink.c:12617
#5  0x555ae503 in ldwrite () at
/home/alecop01/toolchain/src/binutils-gdb/ld/ldwrite.c:545
#6  0x555aadfc in main (argc=2, argv=0x7fffd968) at
/home/alecop01/toolchain/src/binutils-gdb/ld/ldmain.c:513

The assembly here is motivated by GCC's output for the following C testcase:

$ cat t.c
extern __attribute((weak)) __thread int x;
void _start(void) { x = 1; }
$ ./aarch64-linux-gnu-gcc t.c -fpic -nostdlib
/home/alecop01/toolchain/build-aarch64-linux-gnu/install/bin/../lib/gcc/aarch64-linux-gnu/12.0.0/../../../../aarch64-linux-gnu/bin/ld:
BFD (7f92ed6b41c441ab2111c9f1212cbbc13222edcc) 2.37.50.20210927 assertion fail
elfnn-aarch64.c:5084
collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core
dumped
compilation terminated.
$ ./aarch64-linux-gnu-gcc t.c -fpic -nostdlib -c -S -o -
.arch armv8-a
.file   "t.c"
.text
.align  2
.global _start
.type   _start, %function
_start:
.LFB0:
.cfi_startproc
stp x29, x30, [sp, -16]!
.cfi_def_cfa_offset 16
.cfi_offset 29, -16
.cfi_offset 30, -8
mov x29, sp
adrpx0, :tlsdesc:x
ldr x1, [x0, #:tlsdesc_lo12:x]
add x0, x0, :tlsdesc_lo12:x
.tlsdesccallx
blr x1
mrs x1, tpidr_el0
add x0, x1, x0
mov w1, 1
str w1, [x0]
nop
ldp x29, x30, [sp], 16
.cfi_restore 30
.cfi_restore 29
.cfi_def_cfa_offset 0
ret
.cfi_endproc
.LFE0:
.size   _start, .-_start
.weak   x
.ident  "GCC: (d06dc8a2c73735e9496f434787ba4c93ceee5eea) 12.0.0
20210927 (experimental)"
.section.note.GNU-stack,"",@progbits

-- 
You are receiving this mail because:
You are on the CC list for the bug.


[Bug ld/28393] aarch64 ld: assertion fail at elfnn-aarch64.c:5084 with weak undef tlsdesc symbol

2021-09-28 Thread acoplan at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=28393

Alex Coplan  changed:

   What|Removed |Added

 Target||aarch64-linux-gnu

-- 
You are receiving this mail because:
You are on the CC list for the bug.