[Bug ld/32969] Build of BCC fails with relocation of misaligned symbol during link on s390x

2025-05-23 Thread cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=32969

--- Comment #6 from Sourceware Commits  ---
The binutils-2_44-branch branch has been updated by Jens Remus
:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f0019390d12162ea8141efa92246aa615ff5efee

commit f0019390d12162ea8141efa92246aa615ff5efee
Author: Jens Remus 
Date:   Mon May 19 10:38:01 2025 +0200

s390: Prevent GOT access rewrite for misaligned symbols

Dereferences of GOT slots with lgrl or lg for global symbols are
rewritten to larl to get get rid of the extra memory access.  However
this is invalid for:

- symbols marked for absolute addressing
- symbols at odd addresses (larl can handle only even addresses)

Commit e6213e09ed0e ("S/390: Prevent GOT access rewrite for certain
symbols") added checks for the above.  But instead of checking the
address of a symbol for being halfword aligned, it tries to deduce
this from whether the symbol value and section the symbol is defined
in are halfword aligned.  The way it is done has two issues:

1. The use of bfd_section_from_elf_index to obtain the section the
   symbol is defined in may not return the one that remains in the
   output.  For instance for COMDAT sections getting deduplicated
   the section retrieved using bfd_section_from_elf_index may not be
   the same as h->root.u.def.section.  If COMDAT sections of same
   group signature have different alignment properties the wrong
   one may be checked. This may then lead to an erroneous rewrite
   of lgrl %rX, sym@GOTENT to larl %rX, sym, although the symbol in
   the remaining section is not properly aligned, triggering an
   "relocation for misaligned symbol" error at link-time.

   This may for instance occur when mixing C++ modules compiled with
   GCC and Clang, as GCC emits a 2-byte alignment and Clang a 1-byte
   alignment for COMDAT sections containing type information:

 $ cat sample.cpp
 #include 
 struct A {};
 const std::type_info &q() { return typeid(A); }

 $ g++ -c sample.cpp -o sample_gcc.o
 $ clang++ -c sample.cpp -o sample_clang.o
 $ readelf -WS sample_gcc.o sample_clang.o

 Produces (reformatted and reduced):
 File   Name   OffSize   ES Flg Lk Inf Al
 sample_gcc.o   .rodata._ZTS1A 80 04 00  AG  0   0  2
 sample_clang.o .rodata._ZTS1A 58 03 00  AG  0   0  1

2. The symbol may end up at an even address, if both the symbol value
   and the section defining the symbol are 1-byte aligned.  While this
   does not trigger an error, it fails an opportunity to rewrite a GOT
   access.

   In a Linux Kernel build this causes ~15k GOT accesses using lgrl to
   be skipped to be rewritten to larl.

Resolve both issues by simply checking whether the symbol address is
halfword aligned.  Do not check the symbol value nor section defining
the symbol for halfword alignment.

bfd/
PR ld/32969
* elf64-s390.c (elf_s390_relocate_section): Only rewrite
lgrl/lg from GOT to larl if symbol address is halfword aligned.

ld/testsuite/
PR ld/32969
* ld-s390/s390.exp (pr32969_64-1, pr32969_64-2): Add tests for
rewrite of GOT access when COMDAT section deduplication is
involved.
* ld-s390/pr32969_64-1.dd: New test for rewrite of GOT access
when COMDAT section deduplication is involved.
* ld-s390/pr32969_64-2.dd: Likewise.
* ld-s390/pr32969a.s: Likewise.
* ld-s390/pr32969b.s: Likewise.
* ld-s390/pr32969c.s: Likewise.

Bug: https://sourceware.org/PR32969
Fixes: e6213e09ed0e ("S/390: Prevent GOT access rewrite for certain
symbols")
Reported-by: Ilya Leoshkevich 
Signed-off-by: Jens Remus 
(cherry picked from commit ed53e990e57e4f98b42a57b481fc12ad7f55b42e)

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


[Bug binutils/3298] -mrelax broken for sh-elf

2025-05-23 Thread qubos at outlook dot de
https://sourceware.org/bugzilla/show_bug.cgi?id=3298

--- Comment #10 from Quentin Boswank  ---
There seems to be a bug in gas where switch table entris will not emit
R_SH_SWITCH8 relocs when using -ffunction-sections in gcc. The R_SH_CODE/DATA
pair around them however will still get generated.

Minimal example:

.section .text.hi,"ax",@progbits
.align 2
.L1:
.byte .L2-.L1
.align 1
.L2:

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


[Bug binutils/3298] -mrelax broken for sh-elf

2025-05-23 Thread amylaar at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=3298

--- Comment #11 from Joern Rennecke  ---
(In reply to Quentin Boswank from comment #6)
> Created attachment 16079 [details]
> Patch to fix load/store swap crash bug
> 
> I am now able to execute my bare metal binarys (non-PIC)

I see we have similar code in coff-sh.c sh_swap_insns.
Was the bug copied from there, or did it arise because of copying without
accounting for coff/elf reloc differences?

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


[Bug ld/17689] PIE copy relocations handling broken with ld.bfd

2025-05-23 Thread sam at gentoo dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=17689

Sam James  changed:

   What|Removed |Added

   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=64237

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


[Bug ld/32969] Build of BCC fails with relocation of misaligned symbol during link on s390x

2025-05-23 Thread iii at linux dot ibm.com
https://sourceware.org/bugzilla/show_bug.cgi?id=32969

--- Comment #5 from Ilya Leoshkevich  ---
Would it be possible to backport this to binutils 2.44?
This is the version where I found this issue:
https://packages.debian.org/trixie/binutils.

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


[Bug libctf/32903] Error pointer overwritten on successful dict open in ctf_dict_open

2025-05-23 Thread nick.alcock at oracle dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=32903

Nick Alcock  changed:

   What|Removed |Added

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

--- Comment #7 from Nick Alcock  ---
This is now on master. binutils 2.43 and 2.44 are affected, but given the
relatively minor nature of this bug (requiring what was before now a bug in
callers -- inspecting the errp value on success -- to observe) I am not
immediately minded to backport the fix.

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


[Bug libctf/32903] Error pointer overwritten on successful dict open in ctf_dict_open

2025-05-23 Thread cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=32903

--- Comment #6 from Sourceware Commits  ---
The master branch has been updated by Nick Alcock :

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=14303d6295e1bfd8a4e1b447057b78ce583be75d

commit 14303d6295e1bfd8a4e1b447057b78ce583be75d
Author: Nick Alcock 
Date:   Mon May 12 12:31:00 2025 +0100

libctf: archive, open: when opening, always set errp to something

ctf_arc_import_parent, called by the cached-opening machinery used by
ctf_archive_next and archive-wide lookup functions like
ctf_arc_lookup_symbol, has an err-pointer parameter like all other opening
functions.  Unfortunately it unconditionally initializes it whenever
provided, even if there was no error, which can lead to its being
initialized to an uninitialized value.  This is not technically an
API-contract violation, since we don't define what happens to the error
value except when an error happens, but it is still unpleasant.

Initialize it only when there is an actual error, so we never initialize it
to an uninitialized value.

While we're at it, improve all the opening pathways: on success, set errp
to
0, rather than leaving it what it was, reducing the likelihood of
uninitialized error param returns in callers too.  (This is inconsistent
with the treatment of ctf_errno(), but the err value being a parameter
passed in from outside makes the divergence acceptable: in open functions,
you're never going to be overwriting some old error value someone might
want
to keep around across multiple calls, some of which are successful and some
of which are not.)

Soup up existing tests to verify all this.

Thanks to Bruce McCulloch for the original patch, and Stephen Brennan for
the report.

libctf/
PR libctf/32903
* ctf-archive.c (ctf_arc_open_internal): Zero errp on success.
(ctf_dict_open_sections): Zero errp at the start.
(ctf_arc_import_parent): Intialize err.
* ctf-open.c (ctf_bufopen): Zero errp at the start.
* testsuite/libctf-lookup/add-to-opened.c: Make sure one-element
archive opens update errp.
* testsuite/libctf-writable/ctf-compressed.c: Make sure real
archive
opens update errp.

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


[Bug binutils/3298] -mrelax broken for sh-elf

2025-05-23 Thread qubos at outlook dot de
https://sourceware.org/bugzilla/show_bug.cgi?id=3298

--- Comment #12 from Quentin Boswank  ---
Created attachment 16103
  --> https://sourceware.org/bugzilla/attachment.cgi?id=16103&action=edit
Patch for gas bug not creating switch table relocs in alternative code sections

quick 2 liner fix
somewhat expected something like this

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


[Bug binutils/3298] -mrelax broken for sh-elf

2025-05-23 Thread qubos at outlook dot de
https://sourceware.org/bugzilla/show_bug.cgi?id=3298

--- Comment #13 from Quentin Boswank  ---
(In reply to Joern Rennecke from comment #11)
> (In reply to Quentin Boswank from comment #6)
> > Created attachment 16079 [details]
> > Patch to fix load/store swap crash bug
> > 
> > I am now able to execute my bare metal binarys (non-PIC)
> 
> I see we have similar code in coff-sh.c sh_swap_insns.
> Was the bug copied from there, or did it arise because of copying without
> accounting for coff/elf reloc differences?

Could very well be copied over bug but I do not know enought about coff to give
you a resonable answere here

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