When browsing glibc code, I found some code beyong my understanding of C language, it's introduced in this commit. Code is simplified as below.
#include <stdio.h>
int foo(void) {
printf("%s \n", __FUNCTION__);
return 0;
}
int bar(void) asm("foo");
int main(int argc, char *argv[]) {
bar();
return 0;
}
Output:
foo
CodePudding user response:
What's asm labels in C language?
It does not exist in C programming language.
It's a GCC extension to the C language, that basically replaces the function name with another function name upon compilation.
This program:
void bar(void);
void func() { bar(); }
Compiles to:
func:
jmp bar
But this program:
void bar(void) asm("somename");
void func() { bar(); }
Compiles to:
func:
jmp somename
I believe, the idea of the commit is that GLIBC code that tests sqrt will not be optimized by the compiler, so that the test code can test the generic implementation not the built-in compiler implementation the compiler uses to optimize.
