<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/141491>141491</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
1-byte aligned global string leads to unexpected creation of GOT entry
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dominik-steenken
</td>
</tr>
</table>
<pre>
Consider:
```C
#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`:
```asm
larl %r2, msg1
brasl %r14, printf@PLT
larl %r2, msg2
brasl %r14, printf@PLT
```
With `-O1`:
```asm
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`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VU1v4zYQ_TX0ZWCDomzJOujgOHU3wAK7QAPkTIkjiV2KNEjKifvri6GsrJN2gV4KGLDI-XhvZt5IMgTdW8Sa7R7Y7nElpzg4Xys3aqt_rENEtD_QrhqnrvXR2aAVepYfGD-wgs-_Ix1Erm1rJoXA8mOISrvNwPLfyMQPrbMhQjtID2PoM5jBgOWPwIT4gsY4JgTLH_7hKz75vjhvFNsd7bs_4wdtI3TOMbFnogJW0jUAwNlrGzsm9gTKRDUHfLaIDxaPcfIW-C15-Xhf6Qz3MqCF1o1nbbTtIQ46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