This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Win32 Shared libraries and constant arrays
- From: Pascal Obry <obry at act-europe dot fr>
- To: binutils at sources dot redhat dot com
- Date: Sun, 1 Feb 2004 22:24:21 +0100
- Subject: Win32 Shared libraries and constant arrays
Here is the problem. The auto-import feature for non scalar syms works only
if the syms are the DATA section. So for constant arrays this not working.
The following simple example will not work properly:
clib.c:
const char arr[] = "azertyazertyazertyazertyazertyazertyazertyazertyazerty";
$ gcc -shared -o clib.dll clib.c
main.c:
#include <stdio.h>
extern const char arr[];
int main (void)
{
int k;
for (k=0; k<6; k++)
printf ("arr[%d]=%c\n", k, arr[k]);
}
$ gcc -o main main.c clib.dll
$ ./main
arr[0]=ÿ
arr[1]=%
arr[2]=à
arr[3]=`
arr[4]=@
arr[5]=
Of course the obvious fix is to remove the "const" attribute. But this is not
a general solution. The problem occurs, for example, in the standard Ada
libraries where it is not an option to change a constant to a variable (the
spec are part of the standard).
Is there a solution with the current GCC ?
If not a solution would be to add an option to GCC for force all such syms
into the DATA section.
Thoughts ?
Thanks,
Pascal.
--
--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://perso.wanadoo.fr/pascal.obry
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595