This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

static link problems with alias


Hi All,
I've encountered a problem doing a static link due to duplicated symbols error.
I reproduced the scenario with simple test cases as follows (see
attached sources)

I have the following dummy functions:
- int foo();
- foo_alias() as weak alias of foo()
- int bar(); (thats call foo_alias())
all archived into libfoo_alias.a

and the following ones:

int foo();
int other();
archied into libfoo.a

and the main.c calling bar() and other().

When I compile the main with the following command:

gcc -static -L. main.c -lfoo_alias -lfoo I get the following error:

./libfoo.a(foo.o)(.text+0x0): In function `foo':
: multiple definition of `foo'
./libfoo_alias.a(foo_alias.o)(.text+0x0): first defined here
collect2: ld returned 1 exit status

If I modify the bar() function calling foo() instead of the alias, it
successfully linked.

Where I'm going wrong? is the failing path working correctly?

Regards,
Carmelo

P.S.
My env as follows:
Red Hat Enterprise Linux AS 4
gcc version 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)
GNU ld version 2.15.92.0.2 20040927

same behaviour with gcc 4.1.1 and ld 2.17.50
int foo_alias();
int foo();

int  bar() {
return foo_alias();
}
int  foo() {
return 1;
}

int other() {
   return 0;
}

#define weak_alias(name, aliasname) _weak_alias (name, aliasname)
#define _weak_alias(name, aliasname) extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));

int  foo() {
return 0;
}

weak_alias(foo, foo_alias)
int main() {

bar();
other();
return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]