public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* gold doesn't accept object file as script
@ 2011-01-25  7:20 Vladimir Simonov
  2011-01-25 15:15 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Simonov @ 2011-01-25  7:20 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: binutils

Hi Ian,

According "man ld" "If the linker cannot recognize the format
of an object file, it will assume that it is a linker script."

But gold doesn't follow above. For details, see test case below.

Briefly, the command "gcc -fuse-ld=gold -o a.4 -shared exports.ld a.a"
if exports.ld is linker script leads to warning
"exports.ld:1:8: ignoring command OPTION; OPTION is only valid for
scripts specified via -T/--script" and resulted shared library
doesn't contain func_a.
exports.ld contains only EXTERN(func_a)

This feature is used to link func_a (located in static library)
into shared one.

Is it by gold design or a bug?
Should I file it or it is duplicate?

What is the best way to workaround the problem?
--Wl,--undefined=func_a?

Thank you in advance
Vladimir Simonov

$ cat exports.ld
EXTERN(func_a)
$ cat b.sh
#!/bin/bash

PREF=/opt/gcc-4.4.3-glibc-2.3.2/bin/i686-unknown-linux-gnu-

rm -f a.o a.a a.1 a.2 a.3 a.4

${PREF}gcc -c -o a.o -fPIC a.c
${PREF}ar rcs a.a a.o

echo Build shared from obj by bfd
${PREF}gcc -o a.1 -shared a.o
${PREF}readelf -a a.1 | grep func_a

echo Build shared from lib by bfd
${PREF}gcc -o a.2 -shared exports.ld a.a
${PREF}readelf -a a.2 | grep func_a

echo Build shared from obj by gold
${PREF}gcc -fuse-ld=gold -o a.3 -shared a.o
${PREF}readelf -a a.3 | grep func_a

echo Build shared from lib by gold
${PREF}gcc -fuse-ld=gold -o a.4 -shared exports.ld a.a
${PREF}readelf -a a.4 | grep func_a
echo DONE

$ ./b.sh
Build shared from obj by bfd
      1: 000003dc    38 FUNC    GLOBAL DEFAULT   10 func_a
     44: 000003dc    38 FUNC    GLOBAL DEFAULT   10 func_a
Build shared from lib by bfd
      1: 000003dc    38 FUNC    GLOBAL DEFAULT   10 func_a
     44: 000003dc    38 FUNC    GLOBAL DEFAULT   10 func_a
Build shared from obj by gold
      6: 0000043c    38 FUNC    GLOBAL DEFAULT   11 func_a
     27: 0000043c    38 FUNC    GLOBAL DEFAULT   11 func_a
Build shared from lib by gold
/opt/gcc-4.4.3-glibc-2.3.2/bin/../lib/gcc/i686-unknown-linux-gnu/4.4.3/../../../../i686-unknown-linux-gnu/bin/ld.gold: 
warning: exports.ld:1:8: ignoring command OPTION; OPTION is only valid for scripts 
specified via -T/--script
DONE

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

* Re: gold doesn't accept object file as script
  2011-01-25  7:20 gold doesn't accept object file as script Vladimir Simonov
@ 2011-01-25 15:15 ` Ian Lance Taylor
  2011-01-25 16:33   ` Vladimir Simonov
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Lance Taylor @ 2011-01-25 15:15 UTC (permalink / raw)
  To: Vladimir Simonov; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 985 bytes --]

Vladimir Simonov <sv@sw.ru> writes:

> According "man ld" "If the linker cannot recognize the format
> of an object file, it will assume that it is a linker script."
>
> But gold doesn't follow above. For details, see test case below.

That turns out not to be the case.  Gold does implement that.

> Briefly, the command "gcc -fuse-ld=gold -o a.4 -shared exports.ld a.a"
> if exports.ld is linker script leads to warning
> "exports.ld:1:8: ignoring command OPTION; OPTION is only valid for
> scripts specified via -T/--script" and resulted shared library
> doesn't contain func_a.
> exports.ld contains only EXTERN(func_a)

Internally gold implements EXTERN via OPTION, and as the warning says
gold only permits OPTION in a script specified via -T/--script.  So the
bug is that EXTERN is implemented as OPTION.

Fortunately, the fix is simple, as the necessary framework was
introduced for other reasons.  Would you mind giving this patch a try to
see if it fixes your problem?

Ian


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: extern --]
[-- Type: text/x-diff, Size: 922 bytes --]

Index: script.cc
===================================================================
RCS file: /cvs/src/src/gold/script.cc,v
retrieving revision 1.79
diff -u -p -r1.79 script.cc
--- script.cc	3 Nov 2010 17:18:23 -0000	1.79
+++ script.cc	25 Jan 2011 15:13:08 -0000
@@ -2576,12 +2576,8 @@ yyerror(void* closurev, const char* mess
 extern "C" void
 script_add_extern(void* closurev, const char* name, size_t length)
 {
-  // We treat exactly like -u NAME.  FIXME: If it seems useful, we
-  // could handle this after the command line has been read, by adding
-  // entries to the symbol table directly.
-  std::string arg("--undefined=");
-  arg.append(name, length);
-  script_parse_option(closurev, arg.c_str(), arg.size());
+  Parser_closure* closure = static_cast<Parser_closure*>(closurev);
+  closure->script_options()->add_symbol_reference(name, length);
 }
 
 // Called by the bison parser to add a file to the link.

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

* Re: gold doesn't accept object file as script
  2011-01-25 15:15 ` Ian Lance Taylor
@ 2011-01-25 16:33   ` Vladimir Simonov
  2011-01-25 18:55     ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Simonov @ 2011-01-25 16:33 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: binutils

On 01/25/2011 06:15 PM, Ian Lance Taylor wrote:
> Vladimir Simonov<sv@sw.ru>  writes:
>
>> According "man ld" "If the linker cannot recognize the format
>> of an object file, it will assume that it is a linker script."
>>
>> But gold doesn't follow above. For details, see test case below.
>
> That turns out not to be the case.  Gold does implement that.
>
>> Briefly, the command "gcc -fuse-ld=gold -o a.4 -shared exports.ld a.a"
>> if exports.ld is linker script leads to warning
>> "exports.ld:1:8: ignoring command OPTION; OPTION is only valid for
>> scripts specified via -T/--script" and resulted shared library
>> doesn't contain func_a.
>> exports.ld contains only EXTERN(func_a)
>
> Internally gold implements EXTERN via OPTION, and as the warning says
> gold only permits OPTION in a script specified via -T/--script.  So the
> bug is that EXTERN is implemented as OPTION.
>
> Fortunately, the fix is simple, as the necessary framework was
> introduced for other reasons.  Would you mind giving this patch a try to
> see if it fixes your problem?
>
> Ian
>

Perfect. The test is passed.

Thank you a lot.

Vladimir Simonov

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

* Re: gold doesn't accept object file as script
  2011-01-25 16:33   ` Vladimir Simonov
@ 2011-01-25 18:55     ` Ian Lance Taylor
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Lance Taylor @ 2011-01-25 18:55 UTC (permalink / raw)
  To: Vladimir Simonov; +Cc: binutils

Vladimir Simonov <sv@sw.ru> writes:

> On 01/25/2011 06:15 PM, Ian Lance Taylor wrote:
>> Fortunately, the fix is simple, as the necessary framework was
>> introduced for other reasons.  Would you mind giving this patch a try to
>> see if it fixes your problem?
>
> Perfect. The test is passed.

Thanks for testing it.  Committed with this ChangeLog entry.

Ian

2011-01-25  Ian Lance Taylor  <iant@google.com>

	* script.cc (script_add_extern): Rewrite to use
	add_symbol_reference.

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

end of thread, other threads:[~2011-01-25 18:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-25  7:20 gold doesn't accept object file as script Vladimir Simonov
2011-01-25 15:15 ` Ian Lance Taylor
2011-01-25 16:33   ` Vladimir Simonov
2011-01-25 18:55     ` Ian Lance Taylor

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).