Open
Description
Consider:
#include <stdio.h>
const char msg1 [] = "Hello";
const char msg2 [] = "World\n";
int foo() {
printf(msg1);
printf(msg2);
return 0;
}
When compiling this with -fno-PIC
and -O0
/-O1
, respectively, the code changes. With -O0
:
larl %r2, msg1
brasl %r14, printf@PLT
larl %r2, msg2
brasl %r14, printf@PLT
With -O1
:
larl %r2, msg1
brasl %r14, printf@PLT
lgrl %r2, .Lstr@GOT
brasl %r14, puts@PLT
This is done by an optimization in the InstCombiner which replaces printf("foo\n")
with puts("foo")
. That explains the puts
instead of the printf
, but because the optimization needs to remove the \n
from the string, it ends up creating a new string. The alignment of this new string is then set to 1
. However, for the s390x ABI, any symbol whose symbol value is a section offset or an address must be at least 2 byte aligned. Since this is not given here, the new string ends up being rerouted via the GOT, which is not expected.
This should be changed such that the new string constant is emitted with align 2
for s390x
.