Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

[thinLTO] Unable to compile with IFUNC symbol #45458

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR46488
Status NEW
Importance P normal
Reported by Vladislav Khmelevsky (och95@yandex.ru)
Reported on 2020-06-28 08:51:37 -0700
Last modified on 2021-10-21 09:55:13 -0700
Version trunk
Hardware All Linux
CC elia.f.geretto@gmail.com, htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, srhines@google.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
The code example:

$ cat thinlto-ifunc.c
typedef int (*func)(void);

int called(void)
{
    return 1;
}

func resolver(void)
{
    return called;
}

__attribute__ ((ifunc ("resolver"))) int foo(void);

int main(int argc, char *argv[])
{
    foo();
}

$ clang -O3 -flto=thin thinlto-ifunc.c -o out
/usr/bin/ld: /tmp/lto-llvm-1798eb.o: in function `main':
thinlto-ifunc.c:(.text.main+0x2): undefined reference to `resolver'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

And in case if ifunc call is in another C file:
$ clang -O3 -flto=thin thinlto-ifunc.c ex.c -o out
/tmp/lto-llvm-d8c1fd.o: in function `main':
ex.c:(.text.main+0x2): undefined reference to `foo'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Quuxplusone commented 3 years ago

A patch trying to solve this issue is under review: https://reviews.llvm.org/D82745