IBM Z: Handle unaligned symbols
commit6cb2f2c7f36c999590a949f663d6057cbc67271f
authorAndreas Krebbel <krebbel@linux.ibm.com>
Tue, 1 Aug 2023 19:01:19 +0000 (1 21:01 +0200)
committerAndreas Krebbel <krebbel@linux.ibm.com>
Tue, 1 Aug 2023 19:01:33 +0000 (1 21:01 +0200)
treeeb712fd24e11ab01c1333f48a00d57cb9f52d0d0
parent7c09e7e24b0d04857d5880197959e75bda0c489e
IBM Z: Handle unaligned symbols

The IBM Z ELF ABI mandates every symbol to reside on a 2 byte boundary
in order to be able to use the larl instruction. However, in some
situations it is difficult to enforce this, e.g. for common linker
scripts as used in the Linux kernel. This patch introduces the
-munaligned-symbols option. When that option is used, external symbols
without an explicit alignment are considered unaligned and its address
will be pushed into GOT or the literal pool.

If the symbol in the final linker step turns out end up on a 2 byte
boundary the linker is able to take this back and replace the indirect
reference with larl again. This should minimize the effect to symbols
which are actually unaligned in the end.

gcc/ChangeLog:

* config/s390/s390.cc (s390_encode_section_info): Assume external
symbols without explicit alignment to be unaligned if
-munaligned-symbols has been specified.
* config/s390/s390.opt (-munaligned-symbols): New option.

gcc/testsuite/ChangeLog:

* gcc.target/s390/aligned-1.c: New test.
* gcc.target/s390/unaligned-1.c: New test.
gcc/config/s390/s390.cc
gcc/config/s390/s390.opt
gcc/testsuite/gcc.target/s390/aligned-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/s390/unaligned-1.c [new file with mode: 0644]