Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7932 Discussions

icx compilation problem with ipo and inline assembly

Jaka_Bac
Novice
545 Views

Hello,

icx has problems when building FFMpeg with IPO enabled. The problem happens when compiling this file

https://github.com/FFmpeg/FFmpeg/blob/96d2a40b9ee0ddd1844b82c23a074804c316caa5/libavcodec/x86/mlpdsp_init.c

The problem is that this uses some inline ASM labels in the C code. Apparently with IPO disabled this is not an issue possibly since the machine code is generated much earlier. With IPO enabled the labels become undefined symbols at link time.

I have created a toy C file that reproduces the issue unrelated to FFMpeg:

 

#include <stdio.h>

extern char label1;
extern char label2;
extern char label3;

static const void* const jmptable[3] = { &label1, &label2,
                                          &label3 };

static int asmtest(int a) {
    int retval;
    const void* jump = jmptable[a];
    __asm__ volatile(
        "jmp *%1\n\t"
        "label1: \n\t"
        "mov $1,%0 \n\t"
        "jmp label4 \n\t"
        "label2: \n\t"
        "mov $2,%0 \n\t"
        "jmp label4 \n\t"
        "label3: \n\t"
        "mov $3,%0 \n\t"
        "label4:"
        : "=r" (retval)
        : "r" (jump)
        );
    return retval;
}

int main()
{
    printf("%d\n", asmtest(2));
}

 

When building this with IPO enabled you get:

lld-link: error: undefined symbol: label3
>>> referenced by ipotest.c

When building with IPO disabled the sample compiles fine.

Since I was testing on Windows, I also tried to reproduce the issue on Linux by using Godbolt Compiler explorer.

There the sample links fine even with -ipo flag

I suspect that this is actually an issue somewhere in LLVM's LLD and link time code generation.

https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYgATKVpMGoZAFI9AIQuXSS%2BsgJ4BlRugDCqWgFcWDfaRuADJ4DJgAcr4ARpjEIADM8aQADqgKhM4Mnj5%2BEilpGQIhYZEsMXFcdpgOTgJCBEzEBNm%2B/gb2mI6Z9Y0ExRHRsQlJCg1NLbmVo739peUSAJR2qN7EyOwcFvGhyD5YANRm8e6j%2BKgAdAhH2GYaAIK3d5iqBLEM%2B8gIjftGMbRcR2s92e...

0 Kudos
1 Solution
SeshaP_Intel
Moderator
382 Views

Hi,

 

Thank you for your patience. The issue here is that the Windows/COFF version of lld tries to determine if there are undefined symbols before compiling the bitcode files. The compiler cannot parse the ASM code. It looks like a black box to it, So, it will not recognize labels that are defined in the asm code. If there are bitcode files and there is an unresolved reference, Windows lld will exit early to save the time of compiling the bitcode files. The Linux/ELF version of lld does not do this. It only reports the unresolved symbols after all of the bitcode files have been compiled.

 

You can bypass this early exit check in Windows/COFF by adding "/link /force:unresolved" to the linking command. Please refer to the screenshot below for more details.

SeshaP_Intel_0-1700743671098.png

 

Could you please confirm whether we can close this thread from our end?

 

Thanks and Regards,

Pendyala Sesha Srinivas

 

View solution in original post

4 Replies
SeshaP_Intel
Moderator
488 Views

Hi,


Thank you for posting in Intel Communities.


We were able to reproduce your issue. We are working on it internally.

We will get back to you soon.


Thanks and Regards,

Pendyala Sesha Srinivas


SeshaP_Intel
Moderator
383 Views

Hi,

 

Thank you for your patience. The issue here is that the Windows/COFF version of lld tries to determine if there are undefined symbols before compiling the bitcode files. The compiler cannot parse the ASM code. It looks like a black box to it, So, it will not recognize labels that are defined in the asm code. If there are bitcode files and there is an unresolved reference, Windows lld will exit early to save the time of compiling the bitcode files. The Linux/ELF version of lld does not do this. It only reports the unresolved symbols after all of the bitcode files have been compiled.

 

You can bypass this early exit check in Windows/COFF by adding "/link /force:unresolved" to the linking command. Please refer to the screenshot below for more details.

SeshaP_Intel_0-1700743671098.png

 

Could you please confirm whether we can close this thread from our end?

 

Thanks and Regards,

Pendyala Sesha Srinivas

 

Jaka_Bac
Novice
374 Views

Hi Sesha,

 

Thank you for the detailed analysis and the provided workaround

 

Best Regards,

Jaka

0 Kudos
SeshaP_Intel
Moderator
359 Views

Hi,


Thanks for accepting our solution. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.


Thanks and Regards,

Pendyala Sesha Srinivas


0 Kudos
Reply