This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Re: A glibc dynamic linker or gld bug?
Um. The test case wouldn't have made things much clearer because I
sent the wrong version. Try this.
--
Geoffrey Keating <geoffk@ozemail.com.au>
===File ~/glibc-tests/weaktest.c============================
#define CONCAT(x,y) x ## y
#define CONCAT2(x,y) CONCAT(x,y)
#define STRING(x) #x
#define STRING2(x) STRING(x)
#ifdef WEAKDATA
#pragma weak dataitem
#endif
int dataitem = NUM;
int CONCAT2(getdataitem_,NUM)(void)
{
return dataitem;
}
extern int getdataitem_1(void);
extern int getdataitem_2(void);
extern int getdataitem_3(void);
extern int getdataitem_4(void);
#ifdef MAIN
#include <stdio.h>
int main(void)
{
static int (*const (funcs[MAIN]))(void) = {
getdataitem_1,
#if MAIN >= 2
getdataitem_2,
#endif
#if MAIN >= 3
getdataitem_3,
#endif
#if MAIN >= 4
getdataitem_4
#endif
};
int i;
for (i = 0; i < MAIN; i++)
if (funcs[i])
printf("%d ", funcs[i]());
else
printf("NULL ", i+1);
printf("\n");
}
#endif
============================================================
===File ~/glibc-tests/weaktest.sh===========================
#!/bin/sh
set -x
set -e
gcc -c -DNUM=1 weaktest.c -O -o weak1-strong.o
gcc -c -DNUM=1 -DWEAKDATA weaktest.c -O -o weak1-weak.o
gcc -c -DNUM=1 -fpic -DWEAKDATA weaktest.c -O -o weak1-weak-pic.o
gcc -shared -DNUM=2 -DWEAKDATA -fpic weaktest.c -O -o weak2-weak-pic.so
gcc -shared -DNUM=2 -fpic weaktest.c -O -o weak2-strong-pic.so
gcc -c -DNUM=3 -DWEAKDATA -DMAIN=3 weaktest.c -O -o weak3-weak-main.o
gcc weak1-weak.o ./weak2-weak-pic.so weak3-weak-main.o -o weak-w-wp-wm
gcc weak1-weak.o ./weak2-strong-pic.so weak3-weak-main.o -o weak-w-sp-wm
gcc ./weak2-weak-pic.so weak3-weak-main.o weak1-strong.o -o weak-wp-wm-s
gcc ./weak2-strong-pic.so weak3-weak-main.o weak1-strong.o -o weak-sp-wm-s
set +e
./weak-w-wp-wm
./weak-w-sp-wm
./weak-wp-wm-s
./weak-sp-wm-s
============================================================