<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=http://email.email.llvm.org/c/eJylVltzqzgM_jXkRQNDIDce8pCmoZuZbNtp0zmzTxkDhvisgxnbtEl__UpAbj3Z7pnZTNpgSZbkT9JnEpUdps7I777-vePPnGAAqWRlAa77zrURqmwVb0ld2rrTdRroh57v-W7QmqyZLrh1whnsJ6PNaOBWqStFWe_doqw7k63mLIOdyrgkw0oZsW9Vy9JYJiXP7oUmlRPEtdH4PxFdChcZMgvMS1vBuxIZMCeYOEHUmYzv2gfAjz1UPOM5kFljNMsrq8m23RFe2JIGKnDCeww_6ez8fT8IBz5-rmyrL_ud8f0vaTZgYaLg7sIA3KcQ3LwSuHwFV7lH88izfG_Pq1xIjr9OENAZg-CsKaRKJD4w-P7jBBjJhTteiBLyukwtVYudHVUBk6JAXKOBE8zB30f-RTaIGAVBjTPwj9tbPaPS_NaHcsDtx6C0CoZJ4iGKs1OsqjZb2Zx1yJP9SWzqpJUOJpQeaU110qbYJqT2Vj5aVEmrOK0u3avqq3dvZXfVVQ4sy7pgm4fV091stXmK49fFerOe3a0WGye4w0q329xTEGqfNrGLtI-Jhf4wjMbjkX8jxq0D3UgTl5pbecyZirDhZXaVuGfE57FQcGHjsnOX_m6lsFsWZQbXxaYYIuOlbbvxewq47FPDOy-0zSuV5d7D45uLA57-TYbYWEHQPQz8SqsiEdac9yNc6L3oBNcMtd7i8DdIg0DK0HXb3MKUTjC2lNehoZVWWma8QkzoDAiSMCCQoGKYGciZBmZgib5KMJyTPlW7SiBlFWAVmC3TPAOV_MTTgOamlhb34xyVsFjF8CHsFkqFGqmQkDCcaWJ43AODI1xa-NAKfaXIdgUvvUt6eJjPIVPcgN1y0KLYWnyiwAyrUJDiXTBg6LwQxnJ9rvuvfF2k6Ve2JhF2bVexft8LsEbjulki6lEnao3nqjq0KeCWOWkDP-hDrDmHV5XbD8QBYlWXWXNKOuSyTL1jOQhUhJOsTWeNpEiQNoczqtYph1xpBKI6iAaQMmvqYzyA9Zaje_Tw-NR6RAealfZATrB1gL_zstn-5-Jl_sfsEcdyuVqu_wIUxcv14-L1FeKnF5jB8-xlvZy_rWYv8Pz28vz0urjC_IjVbxDyv1PwNVV3PAqDGxx9k1DhJqMexzy-ux7wNBcbHBptcUTSk3in3jsyORNNRyrsTB8_d1VjNPsib5ziSJxdYtzFN8TisptsgB3cXtP_3WW3qeEXXviOFL52_WSJbwDSKFA7NGoajYBnElSeG47TxBLJ25miUyQ1DRhDFhibpqsqRBVtycKgtvDgEaWmpl7MiSXIkJEG6GVDSu_8etFNDXEF17DYV1JpHFEa_hwOqoZK8xw1TUDEaGttZQjgIMZvobJESespjZnFn_j343P0vNgnWXbp_16YVOFQIwURFXzxgdxTJx7yFS50LcI-3uPxTkl8xYmFMTVHLorDwaSXTcMsCiPWY7XdKj2dyZRp1au1nH7jUsr344-LlSAGvHQ8DCdR1NtOJ4yPeRSyEZsMJ_nI9yOf-_54PGB48ed51pMs4dJMnSHeoUHJP6BxQUUe3vf-fwZiikxFZDXu-_1-MPLScZ76k2iQDMb9YZYMsZH4jgnpkR9CvKenjUusq0GlRHI1ZyUzeOuUnDcJY4ZWWMmnIpyMqIx06dDFkIs9FoXuKG6aC-F5OT_dP7eunl6T9rTJ-R8SaEI8>53899</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
i386: call to fixed address in PIC isn't position independent
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Alcaro
</td>
</tr>
</table>
<pre>
```
$ clang --version
Ubuntu clang version 13.0.0-2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ cat a.c
void a()
{
typedef void(*fptr)();
fptr p = (fptr)0x12340000;
p();
}
$ clang a.c -m32 -O3 -fpic -S -o-
.text
.file "a.c"
.globl a # -- Begin function a
.p2align 4, 0x90
.type a,@function
a: # @a
# %bb.0:
pushl %ebx
subl $8, %esp
calll .L0$pb
.L0$pb:
popl %ebx
.Ltmp0:
addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %ebx
calll 305397760
addl $8, %esp
popl %ebx
retl
.Lfunc_end0:
.size a, .Lfunc_end0-a
# -- End function
.ident "Ubuntu clang version 13.0.0-2"
.section ".note.GNU-stack","",@progbits
.addrsig
```
That calll instruction isn't very position independent, is it? As far as I can see, compiling to shared object results in an ELF with no relocations, i.e. silent wrong codegen.
GCC does the right thing and goes via a register:
```
$ gcc --version
gcc (Ubuntu 11.2.0-7ubuntu2) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc a.c -m32 -O3 -fpic -S -o-
.file "a.c"
.text
.p2align 4
.globl a
.type a, @function
a:
.LFB0:
.cfi_startproc
movl $305397760, %eax
jmp *%eax
.cfi_endproc
.LFE0:
.size a, .-a
.ident "GCC: (Ubuntu 11.2.0-7ubuntu2) 11.2.0"
.section .note.GNU-stack,"",@progbits
```
(It also omits the global offset table thing, but that's not part of this bug. Not sure if it's a bug at all.)
Compiler Explorer, if you prefer that: https://godbolt.org/z/Wz6PExbdd
Discovered via https://github.com/rui314/mold/issues/348
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVltvqzgQ_jXkZQQihtwe8pCmoRsp21ZtqtU-RQYb4rMORrZpk_Prdwzk1ma7RbngmfHM57l8kCp2mHrDsPuE914480gMmaRlAb7_zrURqmwVb2ld2rrTdRroR0EYhD5pTdZUF9x60Qz24-FmGPtV5ktR1nu_KOvOZKs5ZbBTjEtnWCkj9q1qWRpLpeTsXmin8khSG42_qeggXCCkFmiQtYJ3JRhQj4w9MulMRnftDeBlDxVnPAdn1hjN8spqZ9vuiC5snQYq8KJ7DD_u7MJ9n0RxiNeVbfVpvze6_wKzSRYCBX8XEfCfIvDzSuDyFX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