I have a function original_fun defined in one file (original_fun.c), and I need to refer to it as global_alias in file use_alias.c. I tried the following:
# set_alias.s
.globl global_alias
.set global_alias, original_fun
// original_fun.c
#include <stdio.h>
void original_fun(int x)
{
printf("original_fun(%d)\n", x);
}
// use_alias.c
extern void global_alias(int x);
int main()
{
global_alias(42);
return 0;
}
But the symbol global_alias is not exported:
$ as set_alias.s -o set_alias.o
$ clang original_fun.c -c -o original_fun.o
$ clang use_alias.c -c -o use_alias.o
$ clang set_alias.o original_fun.o use_alias.o -o result
use_alias.o: In function `main':
use_alias.c:(.text+0x1d): undefined reference to `global_alias'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And objdump reports:
$ objdump -rt set_alias.o
set_alias.o: file format elf32-i386
SYMBOL TABLE:
00000000 l d .text 00000000 .text
00000000 l d .data 00000000 .data
00000000 l d .bss 00000000 .bss
00000000 *UND* 00000000 original_fun
(The motivating example is that original_fun is a mangled C++ name, and I would like to export it under a cleaner name, so that it can be easily used from assembler.)
The GAS manual (http://ift.tt/1CuTkyb) states the following:
If you .set a global symbol, the value stored in the object file is the last value stored into it.
This might be related to my problem, but I am not sure I understand this correctly.
Aucun commentaire:
Enregistrer un commentaire