llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.81k stars 11.91k forks source link

Compiling C inline powerpc 64-bit architecture assembly code with Clang 14.0.0 compiler, error: Undefined temporary symbol .Ltmp2 #93192

Open bethebset opened 5 months ago

bethebset commented 5 months ago

My source code are: int MyOpen(char * filename,int Attrib) {//__NR_open //return syscall(SCN(1024), filename, Attrib, 0777); int fp; asm volatile ( "li 0, 1024\n"
"mr 3, %1\n"
"mr 4, %2\n"
"sc\n"
"mr %0, 3\n"
:"=r"(fp) :"r" (filename),"r" (Attrib) :"memory" ); return fp; }

int main() { int fin = MyOpen("/home/test/hello.c",O_RDONLY ); return 0; } compile with: clang -m64 -target powerpc64-linux-gnu test.c -o test and get ERROR: error: Undefined temporary symbol .Ltmp2 2 warnings and 1 error generated.

On Ubuntu 22.04 Have a powerpc64 cross-compile environment

I'm a rookie and didn't find a good fit on google to solve the problem, please help me!

DimitryAndric commented 5 months ago

First of all, it looks like you are mixing up x64 inline assembly with a powerpc64 target? That is never going to work.

Secondly, have you tried a newer version of clang? 14.0 is very old now. You can try https://godbolt.org/ to experiment with different versions.

bethebset commented 5 months ago

首先,看起来您正在将 x64 内联汇编与 powerpc64 目标混为一谈?这永远行不通。

其次,您是否尝试过较新版本的 clang?14.0 现在已经很旧了。您可以尝试 https://godbolt.org/ 尝试不同的版本。

Sorry, I accidentally posted the wrong code for x64.int MyOpen(char * filename,int Attrib) {//__NR_open //return syscall(SCN(1024), filename, Attrib, 0777); int fp; asm volatile ( "li 0, 1024\n"
"mr 3, %1\n"
"mr 4, %2\n"
"sc\n"
"mr %0, 3\n"
:"=r"(fp) :"r" (filename),"r" (Attrib) :"memory" ); return fp; }

DimitryAndric commented 5 months ago

Yes, this compiles fine with the "powerpc64 clang trunk" setting on Godbolt: https://godbolt.org/z/8aKMdWxEs .

So my next advice would be to try a more recent version of clang. 18.1.5 has been released very recently.

bethebset commented 5 months ago

Yes, this compiles fine with the "powerpc64 clang trunk" setting on Godbolt: https://godbolt.org/z/8aKMdWxEs .

So my next advice would be to try a more recent version of clang. 18.1.5 has been released very recently.

Thanks for the suggestion, I've tried using it for authentication before, I just wanted to see if I could implement it with this release Because I have a rather large llvm 14.0 based project that I want to extend to the powerpc platform, but don't want to do the upgrades

chenzheng1030 commented 5 months ago

I am not sure if there is any new clang 14 releases. From the website https://releases.llvm.org/, looks like when a new "big" release is published, there is no new fix packs for older "big" releases. I would suggest you upgrade your compiler to get a clean compile.

bethebset commented 5 months ago

Yes, this compiles fine with the "powerpc64 clang trunk" setting on Godbolt: https://godbolt.org/z/8aKMdWxEs .

So my next advice would be to try a more recent version of clang. 18.1.5 has been released very recently.

I tried 18.0, and it's the same. It still gives me an error.

bethebset commented 5 months ago

I am not sure if there is any new clang 14 releases. From the website https://releases.llvm.org/, looks like when a new "big" release is published, there is no new fix packs for older "big" releases. I would suggest you upgrade your compiler to get a clean compile.

Thanks a lot,I tried 18.0, and it's the same. It gives me the same error.

chenzheng1030 commented 5 months ago

From https://godbolt.org/z/dPEW7hvnT, seems the case passes with both 18.0 and trunk. Could you please double confirm? Thanks.

llvmbot commented 5 months ago

@llvm/issue-subscribers-backend-powerpc

Author: Qizheng Tian (bethebset)

My source code are: int MyOpen(char * filename,int Attrib) {//__NR_open //return syscall(SCN(1024), filename, Attrib, 0777); int fp; __asm__ __volatile__ ( "li 0, 1024\n" "mr 3, %1\n" "mr 4, %2\n" "sc\n" "mr %0, 3\n" :"=r"(fp) :"r" (filename),"r" (Attrib) :"memory" ); return fp; } int main() { int fin = MyOpen("/home/test/hello.c",O_RDONLY ); return 0; } compile with: clang -m64 -target powerpc64-linux-gnu test.c -o test and get ERROR: error: Undefined temporary symbol .Ltmp2 2 warnings and 1 error generated. On Ubuntu 22.04 Have a powerpc64 cross-compile environment I'm a rookie and didn't find a good fit on google to solve the problem, please help me!
bethebset commented 5 months ago

From https://godbolt.org/z/dPEW7hvnT, seems the case passes with both 18.0 and trunk. Could you please double confirm? Thanks.

Sorry, I realized that it's not this code that's the problem, it should be this section of my code that's the problem

void* another() {
    char *p1, *p2
    unsigned long Offset;
    unsigned long a = 3;

    __asm__ (
        "bl label\n"          
        "label: mflr %0\n"        
        "b pos\n"              
        "pos: lis %1, pos@h\n"    
        "ori %1, %1, pos@l\n"
        : "=r" (p1), "=r" (p2)
        :
        : "memory"
    );
    return (char *)p1 +a;
}
chenzheng1030 commented 5 months ago

https://godbolt.org/z/1nWGGEoeE trunk clang still passes your code.

bethebset commented 5 months ago

https://godbolt.org/z/1nWGGEoeE trunk clang still passes your code.

yes, I've also tried this

bethebset commented 5 months ago

https://godbolt.org/z/1nWGGEoeE trunk clang still passes your code.

Is there something wrong with my inline assembly style? It's fine to write some random nop or other instructions.

chenzheng1030 commented 5 months ago

Is there something wrong with my inline assembly style?

The inline assembly syntax is correct. But there is an unused variable *p2 which is assigned in the asm.

bethebset commented 5 months ago

Is there something wrong with my inline assembly style?

The inline assembly syntax is correct. But there is an unused variable *p2 which is assigned in the asm.

You're right, but I added it and it still compiles wrong!

chenzheng1030 commented 4 months ago

You're right, but I added it and it still compiles wrong!

If you are going to verify your inline assembly syntax, maybe you can try what we tried in previous comment, use the compiler explorer. For your cases, I find all of them are able to compile... So don't know how should we help...