Bug 16895 - building mariadb-5.5.37 with gold - .../libmysql_versions.ld:155:9: invalid use of VERSION in input file
Summary: building mariadb-5.5.37 with gold - .../libmysql_versions.ld:155:9: invalid u...
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-02 01:05 UTC by alex_y_xu
Modified: 2014-10-02 17:23 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
libmysql_versions.ld (2.60 KB, text/x-csrc)
2014-05-02 01:08 UTC, alex_y_xu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description alex_y_xu 2014-05-02 01:05:42 UTC

    
Comment 1 alex_y_xu 2014-05-02 01:08:52 UTC
Created attachment 7578 [details]
libmysql_versions.ld
Comment 2 Cary Coutant 2014-05-02 16:46:29 UTC
You didn't provide a command line, but I'm guessing you need to add a -T option (aka --script) in front of the script. Without that, gold doesn't read the script until it's started processing input files, and by that time, it's too late to process the version script commands.
Comment 3 alex_y_xu 2014-05-02 17:12:30 UTC
(In reply to Cary Coutant from comment #2)
> You didn't provide a command line, but I'm guessing you need to add a -T
> option (aka --script) in front of the script. Without that, gold doesn't
> read the script until it's started processing input files, and by that time,
> it's too late to process the version script commands.

well, you could have clicked to upstream...

	...
	Scanning dependencies of target libmysql
	make[2]: Leaving directory `/usr/local/src/mariadb/bld'
	make -f libmysql/CMakeFiles/libmysql.dir/build.make libmysql/CMakeFiles/libmysql.dir/build
	make[2]: Entering directory `/usr/local/src/mariadb/bld'
	/usr/bin/cmake -E cmake_progress_report /usr/local/src/mariadb/bld/CMakeFiles 
	[ 78%] Building CXX object libmysql/CMakeFiles/libmysql.dir/libmysql_exports_file.cc.o
	cd /usr/local/src/mariadb/bld/libmysql && /usr/bin/g++-4.8   -DHAVE_CONFIG_H -DHAVE_OPENSSL -Dlibmysql_EXPORTS -Wall -O2 -D_FORTIFY_SOURCE=2 -fmessage-length=0 -fstack-protector -march=amdfam10 -mtune=amdfam10 -felide-constructors -fno-exceptions -fno-rtti -Wall -Wno-unused-parameter -fno-exceptions -fno-rtti -O2 -g -DNDEBUG -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1 -fPIC -I/usr/local/src/mariadb/bld/include -I/usr/local/src/mariadb/include -I/usr/local/src/mariadb/libmysql -I/usr/local/src/mariadb/bld/pcre -I/usr/local/src/mariadb/pcre -I/usr/local/src/mariadb/strings -I/usr/local/ssl/include    -O2 -D_FORTIFY_SOURCE=2 -fmessage-length=0 -fstack-protector -march=amdfam10 -mtune=amdfam10 -o CMakeFiles/libmysql.dir/libmysql_exports_file.cc.o -c /usr/local/src/mariadb/bld/libmysql/libmysql_exports_file.cc
	Linking CXX shared library libmysqlclient.so
	cd /usr/local/src/mariadb/bld/libmysql && /usr/bin/cmake -E cmake_link_script CMakeFiles/libmysql.dir/link.txt --verbose=1
	/usr/bin/g++-4.8  -fPIC -Wall -O2 -D_FORTIFY_SOURCE=2 -fmessage-length=0 -fstack-protector -march=amdfam10 -mtune=amdfam10 -felide-constructors -fno-exceptions -fno-rtti -Wall -Wno-unused-parameter -fno-exceptions -fno-rtti -O2 -g -DNDEBUG -DDBUG_OFF -DMY_PTHREAD_FASTMUTEX=1  -Wl,--no-undefined -Wl,--no-undefined -Wl,/usr/local/src/mariadb/bld/libmysql/libmysql_versions.ld   -shared -Wl,-soname,libmysqlclient.so.18 -o libmysqlclient.so.18.0.0 CMakeFiles/libmysql.dir/libmysql_exports_file.cc.o -lpthread libclientlib.a ../dbug/libdbug.a ../strings/libstrings.a ../vio/libvio.a ../mysys/libmysys.a ../mysys_ssl/libmysys_ssl.a -lz /usr/local/ssl/lib64/libssl.so /usr/local/ssl/lib64/libcrypto.so -ldl -ldl ../dbug/libdbug.a ../mysys/libmysys.a ../dbug/libdbug.a ../mysys/libmysys.a -lz -lm ../strings/libstrings.a -lpthread -Wl,-rpath,/usr/local/ssl/lib64: 
	/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: error: /usr/local/src/mariadb/bld/libmysql/libmysql_versions.ld:155:9: invalid use of VERSION in input file
	collect2: error: ld returned 1 exit status
	make[2]: *** [libmysql/libmysqlclient.so.18.0.0] Error 1
	make[2]: Leaving directory `/usr/local/src/mariadb/bld'
	make[1]: *** [libmysql/CMakeFiles/libmysql.dir/all] Error 2
	make[1]: Leaving directory `/usr/local/src/mariadb/bld'
	make: *** [all] Error 2
Comment 4 alex_y_xu 2014-05-02 17:12:51 UTC
^^
Comment 5 vuvova 2014-05-02 17:17:59 UTC
There is no -T (--script), indeed. It is intentional. ld manual says

  3.11 Implicit Linker Scripts
  ============================
  If you specify a linker input file which the linker can not recognize as
  an object file or an archive file, it will try to read the file as a
  linker script.

while -T and --script mean

  `-T SCRIPTFILE'
  `--script=SCRIPTFILE'
       Use SCRIPTFILE as the linker script.  This script replaces `ld''s
       default linker script (rather than adding to it), so COMMANDFILE
       must specify everything necessary to describe the output file.

My intention was, precisely, to *add* to the default linker script, so I could not use -T (--script).

See also the last comment in https://mariadb.atlassian.net/browse/MDEV-5982
Comment 6 Cary Coutant 2014-05-02 19:06:41 UTC
> There is no -T (--script), indeed. It is intentional. ld manual says
>
>   3.11 Implicit Linker Scripts
>   ============================
>   If you specify a linker input file which the linker can not recognize as
>   an object file or an archive file, it will try to read the file as a
>   linker script.
>
> while -T and --script mean
>
>   `-T SCRIPTFILE'
>   `--script=SCRIPTFILE'
>        Use SCRIPTFILE as the linker script.  This script replaces `ld''s
>        default linker script (rather than adding to it), so COMMANDFILE
>        must specify everything necessary to describe the output file.
>
> My intention was, precisely, to *add* to the default linker script, so I could
> not use -T (--script).
>
> See also the last comment in https://mariadb.atlassian.net/browse/MDEV-5982

OK, I see. For gold, using -T works because there is no default linker
script to replace. But coming up with something that works with both
linkers is clearly desirable. I think you could separate your script
into all the stuff before "VERSION { ... }", and leave that in an
implicit linker script, then put everything from the VERSION block
into a separate file and add that with --version-script.

I'll have to do some investigation to figure out how gnu ld handles
this, but in gold, we need to have the version script parsed before we
start processing input files. But we can't parse implicit version
scripts first because we can't tell that they're scripts until we
actually start reading the input files; adding another pass over all
the files just to look for implicit scripts would be impractical.
Besides, implicit scripts that contain INPUT commands need to be
processed in order with all other input files.

-cary
Comment 7 vuvova 2014-05-31 17:43:06 UTC
Thanks. I've tried these workarounds, both using -T and splitting the linker script (moving the version part into a separate file for --version-script).

Both kind of worked, no more linking errors. But the resulting library wasn't the same as with GNU ld. It did not have any symbols in the libmysqlclient_16 version node.