public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* export symbols
@ 2009-04-23 22:43 Alberich de megres
  2009-04-24  3:43 ` Ian Lance Taylor
  0 siblings, 1 reply; 12+ messages in thread
From: Alberich de megres @ 2009-04-23 22:43 UTC (permalink / raw)
  To: gcc-help

Hi,

i got a question about exporting symbols:

two files:

main.c: defines main and f1() and load module on b.c file ( compiled )
b.c : defines f2() which uses f1() after been loaded.

to compile b.c file i use:
gcc -shared -fPIC b.c -o b.so

And to compile main.c:
gcc main.c -o main -ldl -rdynamic

Everything works fine, but  -rdynamic affects to all symbols on main.c

but i just want to export some of symbol on main.c. Is it some way to
control which symbols i export?

here are source code for main.c

-------------------------------------------------------------------
#include <stdio.h>
#include <dlfcn.h>

int main(int argc, char **argv)
{
	int *handler;
	double (*cosine)(double);

	handler=(int*)dlopen("dym.mo", RTLD_LAZY);
	if (!handler) {
		printf( "!!! %s\n", dlerror() );
		return;
  	}
	cosine = dlsym(handler, "cos");
	

	printf("coseno 1 =>%f",cosine(1));

	return 0;

	dlclose(handler);
	
}

int f1()
{
   return 42;
}

-----------------------------------------------------------

and for bc.:


#include <stdio.h>
//#include <dlfcn.h>



double cos(double d)
{

	printf("f1 returns->%e\n",f1());

	return d;
}

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: export symbols
  2009-04-23 22:43 export symbols Alberich de megres
@ 2009-04-24  3:43 ` Ian Lance Taylor
  2009-04-25 21:15   ` Andi Hellmund
  0 siblings, 1 reply; 12+ messages in thread
From: Ian Lance Taylor @ 2009-04-24  3:43 UTC (permalink / raw)
  To: Alberich de megres; +Cc: gcc-help

Alberich de megres <alberich2k5@gmail.com> writes:

> but i just want to export some of symbol on main.c. Is it some way to
> control which symbols i export?

http://sourceware.org/binutils/docs-2.19/ld/VERSION.html

Ian

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: export symbols
  2009-04-24  3:43 ` Ian Lance Taylor
@ 2009-04-25 21:15   ` Andi Hellmund
  2009-07-28 19:31     ` Alberich de megres
  0 siblings, 1 reply; 12+ messages in thread
From: Andi Hellmund @ 2009-04-25 21:15 UTC (permalink / raw)
  To: Alberich de megres; +Cc: gcc-help

Ian Lance Taylor wrote:
> Alberich de megres <alberich2k5@gmail.com> writes:
>
>   
>> but i just want to export some of symbol on main.c. Is it some way to
>> control which symbols i export?
>>     
>
> http://sourceware.org/binutils/docs-2.19/ld/VERSION.html
>
> Ian
>
>   
Beside the versioning of symbols, you could also use use one of the
following ld commands (check out the man page for more details):

--exclude-symbols symbol,symbol,...

--dynamic-list=dynamic-list-file

If you are using gcc for linking, then prepend -Wl, to the command, like
-Wl,--exclude-symbols,...

Hope that helps and best regards,
Andi

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: export symbols
  2009-04-25 21:15   ` Andi Hellmund
@ 2009-07-28 19:31     ` Alberich de megres
  2009-08-02 15:03       ` Alberich de megres
  2009-08-11 16:16       ` Ian Lance Taylor
  0 siblings, 2 replies; 12+ messages in thread
From: Alberich de megres @ 2009-07-28 19:31 UTC (permalink / raw)
  To: Andi Hellmund; +Cc: gcc-help

I know it's been a long since i first send my question.. but i'm still stucked.
Versioning symbols does not add them to dynsym table.

Maybe i explained myself in the wrong way:

- I got host program P, with its functions and i want only one to be
seen by modules (function F).

- In the other side i got a program M (module), that is loaded by P
and then it uses the F function from P.

If i compile with -rdynamic option in gcc, it works fine but it
exports all the functions on .dynsym.

Using versioning, and adding this on my code:

__asm__(".symver F,  F@");

Only adds F@ to .symtab, but not to .dynsym. So when executing the
program i get the following message:

./main: symbol lookup error: ../mod/log: undefined symbol: F


And i tried to  --dynamic-list option.. but with no results.

Any idea or tip??

Thanks!!



On Sat, Apr 25, 2009 at 11:15 PM, Andi Hellmund<mail@andihellmund.com> wrote:
> Ian Lance Taylor wrote:
>> Alberich de megres <alberich2k5@gmail.com> writes:
>>
>>
>>> but i just want to export some of symbol on main.c. Is it some way to
>>> control which symbols i export?
>>>
>>
>> http://sourceware.org/binutils/docs-2.19/ld/VERSION.html
>>
>> Ian
>>
>>
> Beside the versioning of symbols, you could also use use one of the
> following ld commands (check out the man page for more details):
>
> --exclude-symbols symbol,symbol,...
>
> --dynamic-list=dynamic-list-file
>
> If you are using gcc for linking, then prepend -Wl, to the command, like
> -Wl,--exclude-symbols,...
>
> Hope that helps and best regards,
> Andi
>
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: export symbols
  2009-07-28 19:31     ` Alberich de megres
@ 2009-08-02 15:03       ` Alberich de megres
  2009-08-11 16:16       ` Ian Lance Taylor
  1 sibling, 0 replies; 12+ messages in thread
From: Alberich de megres @ 2009-08-02 15:03 UTC (permalink / raw)
  To: Andi Hellmund; +Cc: gcc-help

No one have tried to implement modules on his apps? Or know how to do it?

thanks once again,.. and sorry to insist, but i'm lost here :(


On Tue, Jul 28, 2009 at 9:30 PM, Alberich de
megres<alberich2k5@gmail.com> wrote:
> I know it's been a long since i first send my question.. but i'm still stucked.
> Versioning symbols does not add them to dynsym table.
>
> Maybe i explained myself in the wrong way:
>
> - I got host program P, with its functions and i want only one to be
> seen by modules (function F).
>
> - In the other side i got a program M (module), that is loaded by P
> and then it uses the F function from P.
>
> If i compile with -rdynamic option in gcc, it works fine but it
> exports all the functions on .dynsym.
>
> Using versioning, and adding this on my code:
>
> __asm__(".symver F,  F@");
>
> Only adds F@ to .symtab, but not to .dynsym. So when executing the
> program i get the following message:
>
> ./main: symbol lookup error: ../mod/log: undefined symbol: F
>
>
> And i tried to  --dynamic-list option.. but with no results.
>
> Any idea or tip??
>
> Thanks!!
>
>
>
> On Sat, Apr 25, 2009 at 11:15 PM, Andi Hellmund<mail@andihellmund.com> wrote:
>> Ian Lance Taylor wrote:
>>> Alberich de megres <alberich2k5@gmail.com> writes:
>>>
>>>
>>>> but i just want to export some of symbol on main.c. Is it some way to
>>>> control which symbols i export?
>>>>
>>>
>>> http://sourceware.org/binutils/docs-2.19/ld/VERSION.html
>>>
>>> Ian
>>>
>>>
>> Beside the versioning of symbols, you could also use use one of the
>> following ld commands (check out the man page for more details):
>>
>> --exclude-symbols symbol,symbol,...
>>
>> --dynamic-list=dynamic-list-file
>>
>> If you are using gcc for linking, then prepend -Wl, to the command, like
>> -Wl,--exclude-symbols,...
>>
>> Hope that helps and best regards,
>> Andi
>>
>>
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: export symbols
  2009-07-28 19:31     ` Alberich de megres
  2009-08-02 15:03       ` Alberich de megres
@ 2009-08-11 16:16       ` Ian Lance Taylor
       [not found]         ` <530d01580908120358o7dcb0315ue18e55a88b4a14e9@mail.gmail.com>
  1 sibling, 1 reply; 12+ messages in thread
From: Ian Lance Taylor @ 2009-08-11 16:16 UTC (permalink / raw)
  To: Alberich de megres; +Cc: Andi Hellmund, gcc-help

Alberich de megres <alberich2k5@gmail.com> writes:

> I know it's been a long since i first send my question.. but i'm still stucked.
> Versioning symbols does not add them to dynsym table.
>
> Maybe i explained myself in the wrong way:
>
> - I got host program P, with its functions and i want only one to be
> seen by modules (function F).
>
> - In the other side i got a program M (module), that is loaded by P
> and then it uses the F function from P.
>
> If i compile with -rdynamic option in gcc, it works fine but it
> exports all the functions on .dynsym.
>
> Using versioning, and adding this on my code:
>
> __asm__(".symver F,  F@");
>
> Only adds F@ to .symtab, but not to .dynsym. So when executing the
> program i get the following message:
>
> ./main: symbol lookup error: ../mod/log: undefined symbol: F
>
>
> And i tried to  --dynamic-list option.. but with no results.
>
> Any idea or tip??

I recommend that you look at linker version scripts, which permit you to
set specific symbols to be "local" and "global".  See the linker
documentation.  This approach requires an external list of symbols.  It
does not require any specification in the source code.

Another option is to use the visibility attribute, or the -fvisibility
option.  See the compiler documentation for that.

Ian

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: export symbols
       [not found]         ` <530d01580908120358o7dcb0315ue18e55a88b4a14e9@mail.gmail.com>
@ 2009-08-12 15:08           ` Ian Lance Taylor
  2009-08-14 11:37             ` Alberich de megres
  0 siblings, 1 reply; 12+ messages in thread
From: Ian Lance Taylor @ 2009-08-12 15:08 UTC (permalink / raw)
  To: Diego .; +Cc: Alberich de megres, Andi Hellmund, gcc-help

"Diego ." <eljedi@gmail.com> writes:

> Reading this thread, i got one doubt: when using version scripts, is there
> some way to automate the build of a map file?

I don't understand the question.

Certainly one can automate the building of a version script file in
various ways, e.g., based on the output of nm on the .o files.

Ian

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: export symbols
  2009-08-12 15:08           ` Ian Lance Taylor
@ 2009-08-14 11:37             ` Alberich de megres
  2009-08-14 12:02               ` Andrew Haley
  0 siblings, 1 reply; 12+ messages in thread
From: Alberich de megres @ 2009-08-14 11:37 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: Diego ., Andi Hellmund, gcc-help

Any web or tutorial where explains the basics for that? i really have
a mess with all of this, sorry.

I tried version scripts.. but nothing. Modules could not access to
some calls on core part of my app :((

thanks!!!

On Wed, Aug 12, 2009 at 1:02 PM, Ian Lance Taylor<iant@google.com> wrote:
> "Diego ." <eljedi@gmail.com> writes:
>
>> Reading this thread, i got one doubt: when using version scripts, is there
>> some way to automate the build of a map file?
>
> I don't understand the question.
>
> Certainly one can automate the building of a version script file in
> various ways, e.g., based on the output of nm on the .o files.
>
> Ian
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: export symbols
  2009-08-14 11:37             ` Alberich de megres
@ 2009-08-14 12:02               ` Andrew Haley
  2009-08-16 15:15                 ` Alberich de megres
  0 siblings, 1 reply; 12+ messages in thread
From: Andrew Haley @ 2009-08-14 12:02 UTC (permalink / raw)
  To: Alberich de megres; +Cc: gcc-help

Please don't top-post.

Alberich de megres wrote:
> Ian Lance Taylor<iant@google.com> wrote:
>> "Diego ." <eljedi@gmail.com> writes:
>>
>>> Reading this thread, i got one doubt: when using version scripts,
>>> is there some way to automate the build of a map file?
>>
>> I don't understand the question.
>>
>> Certainly one can automate the building of a version script file in
>> various ways, e.g., based on the output of nm on the .o files.
>>
> Any web or tutorial where explains the basics for that? i really
> have a mess with all of this, sorry.
>
> I tried version scripts.. but nothing. Modules could not access to
> some calls on core part of my app :((

Examples are better than any other way to understand this.

I have appended the version script that we use when building libjava.
It causes symbols beginning with "Jv", "_Jv_", and "_Z" to be
exported, along with "__gcj_personality_v0" and
"__gcj_personality_sj0".

Does this explain what you need to know?

Andrew.



# Anonymous GNU ld version script to hide boehm-gc, libffi and fdlibm
# symbols in libgcj.so.

{
  global: Jv*; _Jv_*; __gcj_personality_v0; __gcj_personality_sj0; _Z*;
  local: *;
};

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: export symbols
  2009-08-14 12:02               ` Andrew Haley
@ 2009-08-16 15:15                 ` Alberich de megres
  2009-08-17 16:24                   ` Andrew Haley
  0 siblings, 1 reply; 12+ messages in thread
From: Alberich de megres @ 2009-08-16 15:15 UTC (permalink / raw)
  To: Andrew Haley; +Cc: gcc-help

On Fri, Aug 14, 2009 at 12:53 PM, Andrew Haley<aph@redhat.com> wrote:
> Please don't top-post.
>
> Alberich de megres wrote:
>> Ian Lance Taylor<iant@google.com> wrote:
>>> "Diego ." <eljedi@gmail.com> writes:
>>>
>>>> Reading this thread, i got one doubt: when using version scripts,
>>>> is there some way to automate the build of a map file?
>>>
>>> I don't understand the question.
>>>
>>> Certainly one can automate the building of a version script file in
>>> various ways, e.g., based on the output of nm on the .o files.
>>>
>> Any web or tutorial where explains the basics for that? i really
>> have a mess with all of this, sorry.
>>
>> I tried version scripts.. but nothing. Modules could not access to
>> some calls on core part of my app :((
>
> Examples are better than any other way to understand this.
>
> I have appended the version script that we use when building libjava.
> It causes symbols beginning with "Jv", "_Jv_", and "_Z" to be
> exported, along with "__gcj_personality_v0" and
> "__gcj_personality_sj0".
>
> Does this explain what you need to know?
>
> Andrew.
>
>
>
> # Anonymous GNU ld version script to hide boehm-gc, libffi and fdlibm
> # symbols in libgcj.so.
>
> {
>  global: Jv*; _Jv_*; __gcj_personality_v0; __gcj_personality_sj0; _Z*;
>  local: *;
> };
>
>

How you compile your library?

I still have the same problem: on my module file everything goes fine,
but on my core app file no API function are added to .dynsym table
(the ones to be used by modules). Using you script i cannot get
modules to access some funtions on core side, they only are added to
.symtab table.

thanks once again!!!

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: export symbols
  2009-08-16 15:15                 ` Alberich de megres
@ 2009-08-17 16:24                   ` Andrew Haley
  2009-08-31 23:02                     ` Alberich de megres
  0 siblings, 1 reply; 12+ messages in thread
From: Andrew Haley @ 2009-08-17 16:24 UTC (permalink / raw)
  To: Alberich de megres; +Cc: gcc-help

Alberich de megres wrote:
> On Fri, Aug 14, 2009 at 12:53 PM, Andrew Haley<aph@redhat.com> wrote:
>> Please don't top-post.
>>
>> Alberich de megres wrote:
>>> Ian Lance Taylor<iant@google.com> wrote:
>>>> "Diego ." <eljedi@gmail.com> writes:
>>>>
>>>>> Reading this thread, i got one doubt: when using version scripts,
>>>>> is there some way to automate the build of a map file?
>>>> I don't understand the question.
>>>>
>>>> Certainly one can automate the building of a version script file in
>>>> various ways, e.g., based on the output of nm on the .o files.
>>>>
>>> Any web or tutorial where explains the basics for that? i really
>>> have a mess with all of this, sorry.
>>>
>>> I tried version scripts.. but nothing. Modules could not access to
>>> some calls on core part of my app :((
>> Examples are better than any other way to understand this.
>>
>> I have appended the version script that we use when building libjava.
>> It causes symbols beginning with "Jv", "_Jv_", and "_Z" to be
>> exported, along with "__gcj_personality_v0" and
>> "__gcj_personality_sj0".
>>
>> Does this explain what you need to know?
>> # Anonymous GNU ld version script to hide boehm-gc, libffi and fdlibm
>> # symbols in libgcj.so.
>>
>> {
>>  global: Jv*; _Jv_*; __gcj_personality_v0; __gcj_personality_sj0; _Z*;
>>  local: *;
>> };
>>
>>
> 
> How you compile your library?

It's complicated, but all the information is in gcc/libjava.

> I still have the same problem: on my module file everything goes fine,
> but on my core app file no API function are added to .dynsym table
> (the ones to be used by modules). Using you script i cannot get
> modules to access some funtions on core side, they only are added to
> .symtab table.
> 
> thanks once again!!!

We have got beyond the point where any progress can be made by talking
about this in the abstract.  You need to produce a detailed test case that
someone eles can run which shows the problem.  The smaller and simpler the
test case, the more likely people will help you.

Andrew.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: export symbols
  2009-08-17 16:24                   ` Andrew Haley
@ 2009-08-31 23:02                     ` Alberich de megres
  0 siblings, 0 replies; 12+ messages in thread
From: Alberich de megres @ 2009-08-31 23:02 UTC (permalink / raw)
  To: Andrew Haley; +Cc: gcc-help

On Mon, Aug 17, 2009 at 11:52 AM, Andrew Haley<aph@redhat.com> wrote:
> Alberich de megres wrote:
>> On Fri, Aug 14, 2009 at 12:53 PM, Andrew Haley<aph@redhat.com> wrote:
>>> Please don't top-post.
>>>
>>> Alberich de megres wrote:
>>>> Ian Lance Taylor<iant@google.com> wrote:
>>>>> "Diego ." <eljedi@gmail.com> writes:
>>>>>
>>>>>> Reading this thread, i got one doubt: when using version scripts,
>>>>>> is there some way to automate the build of a map file?
>>>>> I don't understand the question.
>>>>>
>>>>> Certainly one can automate the building of a version script file in
>>>>> various ways, e.g., based on the output of nm on the .o files.
>>>>>
>>>> Any web or tutorial where explains the basics for that? i really
>>>> have a mess with all of this, sorry.
>>>>
>>>> I tried version scripts.. but nothing. Modules could not access to
>>>> some calls on core part of my app :((
>>> Examples are better than any other way to understand this.
>>>
>>> I have appended the version script that we use when building libjava.
>>> It causes symbols beginning with "Jv", "_Jv_", and "_Z" to be
>>> exported, along with "__gcj_personality_v0" and
>>> "__gcj_personality_sj0".
>>>
>>> Does this explain what you need to know?
>>> # Anonymous GNU ld version script to hide boehm-gc, libffi and fdlibm
>>> # symbols in libgcj.so.
>>>
>>> {
>>>  global: Jv*; _Jv_*; __gcj_personality_v0; __gcj_personality_sj0; _Z*;
>>>  local: *;
>>> };
>>>
>>>
>>
>> How you compile your library?
>
> It's complicated, but all the information is in gcc/libjava.
>
>> I still have the same problem: on my module file everything goes fine,
>> but on my core app file no API function are added to .dynsym table
>> (the ones to be used by modules). Using you script i cannot get
>> modules to access some funtions on core side, they only are added to
>> .symtab table.
>>
>> thanks once again!!!
>
> We have got beyond the point where any progress can be made by talking
> about this in the abstract.  You need to produce a detailed test case that
> someone eles can run which shows the problem.  The smaller and simpler the
> test case, the more likely people will help you.
>
> Andrew.
>

Hi again!!


I got  2 files:

main.c: defines main and f1() and load module on b.c file ( compiled )
b.c : defines f2() which uses f1() after been loaded.

Here you have the steps to reproduce the error:

to compile b.c file i use:
gcc -shared -fPIC b.c -o b.so

And to compile main.c:
gcc main.c -o main -g -fPIC -O2 -ldl -Wl,--version-script=vs.txt

When i execute main i get this error:
./main: symbol lookup error: ./b.so: undefined symbol: f1

If we do now:
readelf -s main

I noticed tha f1 symbol is not on .dymsyn table. But if i use
-rdynamic when compiling main.c i got f1 on this tables (dynsym), and
the execution doesn't fail.


And the source code for the files:

----  MAIN.C  ---------------------------------------------------------------
#include <stdio.h>
#include <dlfcn.h>

int main(int argc, char **argv)
{
       int *handler;
       double (*cosine)(double);

       handler=(int*)dlopen("dym.mo", RTLD_LAZY);
       if (!handler) {
               printf( "!!! %s\n", dlerror() );
               return;
       }
       cosine = dlsym(handler, "cos");


       printf("coseno 1 =>%f",cosine(1));

       return 0;

       dlclose(handler);

}

int f1()
{
  return 42;
} __attribute__((visibility ("default")))

-----  B.C  ------------------------------------------------------



#include <stdio.h>
//#include <dlfcn.h>



double cos(double d)
{

       printf("f1 returns->%e\n",f1());

       return d;
}

-----  vs.txt  ------------------------------------------------------

{
    global: f1;
    local: *;
};


Thanks!!!

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-08-31 15:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-23 22:43 export symbols Alberich de megres
2009-04-24  3:43 ` Ian Lance Taylor
2009-04-25 21:15   ` Andi Hellmund
2009-07-28 19:31     ` Alberich de megres
2009-08-02 15:03       ` Alberich de megres
2009-08-11 16:16       ` Ian Lance Taylor
     [not found]         ` <530d01580908120358o7dcb0315ue18e55a88b4a14e9@mail.gmail.com>
2009-08-12 15:08           ` Ian Lance Taylor
2009-08-14 11:37             ` Alberich de megres
2009-08-14 12:02               ` Andrew Haley
2009-08-16 15:15                 ` Alberich de megres
2009-08-17 16:24                   ` Andrew Haley
2009-08-31 23:02                     ` Alberich de megres

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).