From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31027 invoked by alias); 6 Jun 2012 15:32:37 -0000 Received: (qmail 31019 invoked by uid 22791); 6 Jun 2012 15:32:37 -0000 X-SWARE-Spam-Status: No, hits=-5.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-ee0-f47.google.com (HELO mail-ee0-f47.google.com) (74.125.83.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 06 Jun 2012 15:32:23 +0000 Received: by eekd49 with SMTP id d49so2529720eek.20 for ; Wed, 06 Jun 2012 08:32:22 -0700 (PDT) Received: by 10.14.119.138 with SMTP id n10mr10802322eeh.38.1338996742213; Wed, 06 Jun 2012 08:32:22 -0700 (PDT) Received: from [192.168.1.26] (252.Red-88-13-203.dynamicIP.rima-tde.net. [88.13.203.252]) by mx.google.com with ESMTPS id y3sm505567eem.16.2012.06.06.08.32.20 (version=SSLv3 cipher=OTHER); Wed, 06 Jun 2012 08:32:21 -0700 (PDT) Message-ID: <4FCF77ED.40407@gmail.com> Date: Wed, 06 Jun 2012 15:32:00 -0000 From: =?ISO-8859-1?Q?=C1ngel_Gonz=E1lez?= User-Agent: Thunderbird MIME-Version: 1.0 To: DamienDaG CC: gcc-help@gcc.gnu.org Subject: Re: Rename symbol at link time References: <33968382.post@talk.nabble.com> In-Reply-To: <33968382.post@talk.nabble.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2012-06/txt/msg00048.txt.bz2 On 06/06/12 09:27, DamienDaG wrote: > Hi > > I'm trying to build a very simple project composed of one source file and a > linker script : > (...) > 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. > > Can anybody help me ? > > Thanks in advance > > Damien Works for me on Linux. Just with that code I get undefined reference to `puts' (puts instead of printf due to a gcc optimization), which was solved just by adding -L/usr/lib -lc, and then I needed to add -dynamic-linker because the default interpreter was the missing /lib/ld64.so.1 (that's ELF specific, as you're building a PE you don't need to worry). It dies by sigkill as soon as i try to run it, though :S Adding crti.o crtbegin.o crtend.o crtn.o doesn't solve the crashing. I tried adding a dummy to make an alias, and it worked: Just create a file link.s with content: -- begin file -- .global fct1_wrongname .set fct1_wrongname, fct9 fct1_wrongname: -- end of file-- And add it to the compilation *before* f1.c: gcc link.s f1.c -o rename.exe (there are probably many things wrong with this approach, but it apparently works)