public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: DamienDaG <deusnei-div@yahoo.fr>
To: gcc-help@gcc.gnu.org
Subject: Re: Rename symbol at link time
Date: Wed, 06 Jun 2012 10:59:00 -0000	[thread overview]
Message-ID: <33969222.post@talk.nabble.com> (raw)
In-Reply-To: <CAKw7uViQVpGx+K3jvsPFhuGm5bKQuu1X326s4q8+-08Xy2h_Gw@mail.gmail.com>



Václav Zeman wrote:
> 
> On 6 June 2012 10:12, DamienDaG wrote:
>>
>>
>>
>> Václav Zeman wrote:
>>>
>>> On 6 June 2012 09:27, DamienDaG wrote:
>>>>
>>>> Hi
>>>>
>>>> I'm trying to build a very simple project composed of one source file
>>>> and
>>>> a
>>>> linker script :
>>>>
>>>> file f1.c :
>>>> #include <stdio.h>
>>>>
>>>> extern void fct1_wrongname();
>>>>
>>>> void fct9()
>>>> {
>>>>        printf("I'm fct9\n");
>>>> }
>>>>
>>>> int main( int argc, char** argv)
>>>> {
>>>>        fct1_wrongname();
>>>>        return 0;
>>>> }
>>>> end of file f1.c
>>>>
>>>> This file is compiled with command :
>>>> gcc -O0 -xc -g -Wall -c f1.c -of1.o
>>>> then build with :
>>>> ld -T'Link.cmd' -O0 -Map out.map -o rename.exe f1.o
>>>>
>>>> file Link.cmd contains :
>>>>
>>>> fct1_wrongname = fct9 ;
>>>>
>>>> end of file Link.cmd
>>>>
>>>>
>>>> Function fct1_wrongname doesn't exist, and I want to replace the call
>>>> of
>>>> this function by a call of fct9.
>>>>
>>>> I always get this error message :
>>>> Link.cmd:4: undefined symbol `fct9' referenced in expression
>>>>
>>>> I need to use a linker script (here Link.cmd) to apply this to a larger
>>>> project, and I can't use symbol definition (i.e.
>>>> -D"fct1_wrongname=fct9")
>>>> because there are to many symbols.
>>>> I've been looking for a solution for a long time, but I couldn't find
>>>> anything.
>>> Is it possible that the linker script should contain leading
>>> underscores for the symbols? E.g., _fct1_wrongname=_fct9? Take a look
>>> at nm -AB output for the f1.o file.
>>>
>>> --
>>> VZ
>>>
>>>
>>
>> I tried many combinations with/without leanding underscores :
>> with
>> _fct1_wrongname = fct9 ;
>> I get
>> Link.cmd:4: undefined symbol `fct9' referenced in expression
>>
>> with
>> _fct1_wrongname = _fct9 ;
>> and
>> fct1_wrongname = _fct9 ;
>> I get
>> ld: BFD 2.13 assertion fail ../../src/bfd/stabs.c:783
>>
>> nm -AB f1.o outputs :
>> $ nm -AB f1.o
>> f1.o:00000000 b .bss
>> f1.o:00000000 d .data
>> f1.o:00000000 N .stab
>> f1.o:00000000 N .stabstr
>> f1.o:00000000 t .text
>> f1.o:         U ___main
>> f1.o:         U __alloca
>> f1.o:         U _fct1_wrongname
>> f1.o:         U _fct2
>> f1.o:00000012 T _fct9
>> f1.o:0000002a T _main
>> f1.o:         U _printf
> I think I do not entirely understand your use case but wouldn't using
> the alias attribute (see
> http://gcc.gnu.org/onlinedocs/gcc-4.7.0/gcc/Function-Attributes.html#Function-Attributes)
> do what you want?
> 
> -- 
> VZ
> 
> 

I my case I'd like to replace a call to a function that doesn't exist by a
call to an existing function. This is to be applied to a project where a
function is called with a name (e.g. fct1_wrongname in my example), but is
implemented with another name (e.g. fct9). Since I cannot modify source
code, I'd like to make this with the help of a linker script.
It looks strange but in the final project, a part of the code calling
fct1_wrongname is generated automatically, so I cannot modify it.

I'm afraid I cannot use alias as you mentioned because it makes me modify
source code. 
In my example, I need to "rename" function. Eventually I'll need to "rename"
variables as well.

Damien
-- 
View this message in context: http://old.nabble.com/Rename-symbol-at-link-time-tp33968382p33969222.html
Sent from the gcc - Help mailing list archive at Nabble.com.

  reply	other threads:[~2012-06-06 10:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-06  7:27 DamienDaG
2012-06-06  7:54 ` Václav Zeman
2012-06-06  8:13   ` DamienDaG
2012-06-06  9:29     ` Václav Zeman
2012-06-06 10:59       ` DamienDaG [this message]
2012-06-06 20:00         ` Thomas Martitz
2012-06-07  5:04     ` Ian Lance Taylor
2012-06-07  8:59       ` DamienDaG
2012-06-08  9:59         ` Václav Zeman
2012-06-08 10:56           ` DamienDaG
2012-06-06 15:32 ` Ángel González

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33969222.post@talk.nabble.com \
    --to=deusnei-div@yahoo.fr \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).