GCC 3.3 and up on AIX 5.2 correctly detect that the native assembler and linker finally support weak symbols (though there are still issues...). But collect2 doesn't recognize any weak exported symbol as being exported, so GCC's C++ libraries, wind up with Important Things inaccessible. Here's a simple testcase, using only C, to show the problem: % cat >lib.c <<'EOF' int __attribute__ ((weak)) a = 20; int foo (void) { return a; } EOF % cat >prog.c <<'EOF' extern int a; int main(int argc,char ** argv) { return a; } EOF Compiled using: % gcc -shared -o liblib.so lib.c % gcc -Wl,-brtl,-bnortllib -o prog prog.c -L. -llib ld: 0711-317 ERROR: Undefined symbol: a ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. collect2: ld returned 8 exit status If we examine the static symbol table of liblib.so, we see 'a' is present and marked weak as expected: % dump -tv liblib.so | grep ' a' [2] m 0x20000340 .data 1 unamex a [14] m 0x20000290 .data 1 weak a But the dynamic symbol table does not have 'a': % dump -Tv liblib.so | grep ' a' [no output] I have updated collect2.c to recognize AIX's C_WEAKEXT and consider such symbols candidates for exporting. The patch will be attached after I open this. With the patch, the dynamic symbol table becomes: [1] 0x20000290 .data wEXP RW Ldef [noIMid] a (Also, the unused function foo is no longer required to fool linker into keeping 'a'.)
Created attachment 5181 [details] Patch to teach collect2.c to recognize AIX C_WEAKEXT symbols.
Patches should go to gcc-patches@gcc.gnu.org as not every maintainer reads bugs (do not know why), also patches need to be from the head of the tree of the cvs.
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg00731.html
Subject: Bug 13150 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: dje@gcc.gnu.org 2003-12-08 19:02:43 Modified files: gcc : ChangeLog collect2.c Log message: PR target/13150 * collect2.c (GCC_OK_SYMBOL): Add support for AIX C_WEAKEXT. (GCC_UNDEF_SYMBOL): Same. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.831&r2=1.16114.2.832 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/collect2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.142.4.2&r2=1.142.4.3