<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/111338>111338</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[ppc64le] Clang-18 emits machine code that cannot be linked with GNU ld
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rui314
</td>
</tr>
</table>
<pre>
It looks like clang-18 creates an object file that cannot be linked with GNU ld. To see the issue, you can just run the following shell script on a PPC64LE machine (or, alternatively you can run it with `docker run --platform ppc64le --rm -it -v /home/ruiu/mold:/mold ubuntu:24.04`).
```shell
CC=clang-18
cat <<EOF | $CC -c -fPIC -o a.o -xc -
void foo();
void (*get_foo())() { return foo; }
EOF
$CC -shared -o b.so a.o
cat <<EOF | $CC -c -fno-PIE -o c.o -xc -
#include <stdio.h>
__attribute__((ifunc("resolve_foo"))) void foo(void);
void real_foo(void) { printf("foo "); }
void (*resolve_foo())() { return real_foo; }
void (*get_foo())();
int main() {
printf("%p\n", foo);
}
EOF
$CC -o exe ./c.o ./b.so -no-pie
./exe
```
The error is shown below.
```
$ bash -x bug.sh
+ CC=clang-18
+ cat
+ clang-18 -c -fPIC -o a.o -xc -
+ clang-18 -shared -o b.so a.o
+ cat
+ clang-18 -c -fno-PIE -o c.o -xc -
+ clang-18 -o exe ./c.o ./b.so -no-pie
./c.o: in function `main':
-:(.text+0x94): R_PPC64_TOC16_HA for indirect function `foo' unsupported
/usr/bin/ld: ./c.o: R_PPC64_TOC16_HA against foo is not supported by glibc as a dynamic relocation
-:(.text+0x98): R_PPC64_TOC16_LO for indirect function `foo' unsupported
clang-18: error: linker command failed with exit code 1 (use -v to see invocation)
```
The above error doesn't occur if you built the code with GCC. When I compare the LLVM's object file with GCC-generated one, I noticed that GCC generates different code for ifunc functions. I believe LLVM should generate the same code as GCC's.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.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