diff options
| author | 2025-12-13 14:21:22 +0100 | |
|---|---|---|
| committer | 2025-12-13 14:24:30 +0100 | |
| commit | 854df54e1839c8b96d1aaa9aeaa32c2ebbf535f8 (patch) | |
| tree | ba0d2d8b79300d0af2a53aeccd628111733ae7e8 /test/15-reloc.c | |
| parent | 17e5a9f573b1a60e12ed60948f45f5992914d324 (diff) | |
fix position independent loads of function symbols.
For `extern int x[1];`, can use PCREL32 for &x. But for `extern int
x(int)`, must use GOTREL, when not being called directly (that's PLT).
Therefore the type of an external symbol (actually just whether it
denotes a function) matters when deciding what kind of relocation to
emit, so keep that information.
Diffstat (limited to 'test/15-reloc.c')
| -rw-r--r-- | test/15-reloc.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/15-reloc.c b/test/15-reloc.c new file mode 100644 index 0000000..8d1b323 --- /dev/null +++ b/test/15-reloc.c @@ -0,0 +1,29 @@ +/* EXPECT: +1.3 +5 +ok +*/ + +const void *const relro = &relro; +float get_value(unsigned x) { + static const float values [] = {1.1f, 1.2f, 1.3f, 1.4f}; + return x < 4 ? values[x] : 0.0f; +} + +static const short tb[] = { 1,3,34,5,23,2,5,5,-7 }; +static const short *ptb = &tb[4]; + +static int ou(int k) { return ptb[k]; } + +int (*(getputs(void)))(const char *) { + extern int puts(const char *); + int (*t)(const char *) = puts; + return t; +} + +#include <stdio.h> +int main() { + printf("%g\n", get_value(2)); + printf("%d\n", ou(2)); + getputs()("ok"); +} |