Bug 13150 - WEAK symbols not exported by collect2
Summary: WEAK symbols not exported by collect2
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.3.2
: P2 normal
Target Milestone: 3.3.3
Assignee: David Edelsohn
Depends on:
Reported: 2003-11-21 16:03 UTC by Graham Reed
Modified: 2003-12-08 19:48 UTC (History)
1 user (show)

See Also:
Host: powerpc-ibm-aix5.2.0.0
Target: powerpc-ibm-aix5.2.0.0
Build: powerpc-ibm-aix5.2.0.0
Known to work:
Known to fail:
Last reconfirmed: 2003-12-06 19:10:16

Patch to teach collect2.c to recognize AIX C_WEAKEXT symbols. (417 bytes, patch)
2003-11-21 16:04 UTC, Graham Reed
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Graham Reed 2003-11-21 16:03:36 UTC
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; }
% cat >prog.c <<'EOF'
extern int a;
int main(int argc,char ** argv) { return a; }

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
Comment 1 Graham Reed 2003-11-21 16:04:40 UTC
Created attachment 5181 [details]
Patch to teach collect2.c to recognize AIX C_WEAKEXT symbols.
Comment 2 Andrew Pinski 2003-11-21 16:08:42 UTC
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.
Comment 4 CVS Commits 2003-12-08 19:02:49 UTC
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.