https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64420

            Bug ID: 64420
           Summary: LTO can miscompile IFUNCs designated via top-level asm
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amonakov at gcc dot gnu.org

Minimal testcase:

$ cat >test.c <<EOF
#ifdef USE_ASM
void *f_resolver() asm("f");
asm(".type f, %gnu_indirect_function");
void *g_resolver() asm("g");
asm(".type g, %gnu_indirect_function");
#else
int f() __attribute__((ifunc("f_resolver")));
int g() __attribute__((ifunc("g_resolver")));
#endif

static int (*fptr)();
static int (*gptr)();

void *f_resolver() { return fptr; }
void *g_resolver() { return gptr; }
EOF

$ gcc test.c -fPIC -shared -flto -flto-partition=max

$ nm a.out |grep [fg]$
0000000000000750 i f
0000000000000740 i g

$ gcc test.c -fPIC -shared -flto -flto-partition=max -DUSE_ASM

$ nm a.out |grep [fg]$
00000000000006f0 T f
00000000000006e0 i g

Due to LTO partitioning, asm directive and function body can end up in
different assembly files.  The result of such translation will correctly link
without any diagnostics, and fail only at runtime.

This can be a problem for projects using top-level asms to designate ifuncs,
for example in order to avoid bumping the minimum required gcc version to 4.7.

Were there plans to disable LTO partitioning in TUs that contain top-level
asms?

Reply via email to