Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad order of linker arguments #13317

Closed
herrhotzenplotz opened this issue Apr 8, 2024 · 6 comments
Closed

Bad order of linker arguments #13317

herrhotzenplotz opened this issue Apr 8, 2024 · 6 comments

Comments

@herrhotzenplotz
Copy link

I did this

Environment:

indium% echo $CFLAGS
-Xa -xtarget=generic64 -xarch=generic64 -KPIC -xO5 -xregs=no%appl -erroff=E_TOKENLESS_MACRO,E_NONPORTABLE_BIT_FIELD_TYPE
indium% echo $CPPFLAGS
-D__EXTENSIONS__ -I/opt/sn/include
indium% echo $LDFLAGS
-L/opt/sn/lib -L/opt/sn/lib/64 -R/opt/sn/lib:/opt/sn/lib/64
indium% echo $LIBS

indium% echo $CC
cc
indium%

I ran the following configure line:

$ ./configure --prefix=/opt/sn --disable-silent-rules --disable-dependency-tracking --with-openssl --with-ca-bundle=/opt/sn/ssl/certs/cacert.pem

...

  Host setup:       sparc-sun-solaris2.11
  Install prefix:   /opt/sn
  Compiler:         cc
   CFLAGS:          -Xa -xtarget=generic64 -xarch=generic64 -KPIC -xO5 -xregs=no%appl -erroff=E_TOKENLESS_MACRO,E_NONPORTABLE_BIT_FIELD_TYPE
   CPPFLAGS:        -D__EXTENSIONS__ -I/opt/sn/include -I/usr/sfw/include
   LDFLAGS:         -L/opt/sn/lib -L/opt/sn/lib/64 -R/opt/sn/lib:/opt/sn/lib/64 -L/usr/sfw/lib
   LIBS:            -lssl -lcrypto -lssl -lcrypto -lsocket -lnsl -ldl -lldap -lz -lrt -lsocket -lnsl

  curl version:     8.7.1
  SSL:              enabled (OpenSSL v3+)
  SSH:              no      (--with-{libssh,libssh2})
  zlib:             enabled
  brotli:           no      (--with-brotli)
  zstd:             no      (--with-zstd)
  GSS-API:          no      (--with-gssapi)
  GSASL:            no      (libgsasl not found)
  TLS-SRP:          enabled
  resolver:         POSIX threaded
  IPv6:             enabled
  Unix sockets:     enabled
  IDN:              no      (--with-{libidn2,winidn})
  Build docs:       enabled (--disable-docs)
  Build libcurl:    Shared=yes, Static=yes
  Built-in manual:  enabled
  --libcurl option: enabled (--disable-libcurl-option)
  Verbose errors:   enabled (--disable-verbose)
  Code coverage:    disabled
  SSPI:             no      (--enable-sspi)
  ca cert bundle:   /opt/sn/ssl/certs/cacert.pem
  ca cert path:     no
  ca fallback:      no
  LDAP:             enabled (ancient OpenLDAP)
  LDAPS:            enabled
  RTSP:             enabled
  RTMP:             no      (--with-librtmp)
  PSL:              no      (--with-libpsl)
  Alt-svc:          enabled (--disable-alt-svc)
  Headers API:      enabled (--disable-headers-api)
  HSTS:             enabled (--disable-hsts)
  HTTP1:            enabled (internal)
  HTTP2:            no      (--with-nghttp2)
  HTTP3:            no      (--with-ngtcp2 --with-nghttp3, --with-quiche, --with-openssl-quic, --with-msh3)
  ECH:              no      (--enable-ech)
  WebSockets:       no      (--enable-websockets)
  Protocols:        DICT FILE FTP FTPS GOPHER GOPHERS HTTP HTTPS IMAP IMAPS IPFS IPNS LDAP LDAPS MQTT POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP
  Features:         AsynchDNS HSTS HTTPS-proxy IPv6 Largefile NTLM SSL TLS-SRP UnixSockets alt-svc libz threadsafe

grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .
indium% 

Notice the funny grep: illegal option -- E on this system :-)

The build fails completely when using the included xpg4 make. Using schily smake works until:

$ /opt/schily/bin/smake

...
indium% /opt/schily/bin/smake
Making all in lib
smake: WARNING: Nonportable ':=' assignment found for macro 'TIDY' in line 1534 col 4 of 'Makefile'
.../opt/schily/bin/smake  all-am
smake: WARNING: Nonportable ':=' assignment found for macro 'TIDY' in line 1534 col 4 of 'Makefile'
.../bin/bash ../libtool  --tag=CC    --mode=link cc  -xldscope=hidden  -Xa -xtarget=generic64 -xarch=generic64 -KPIC -xO5 -xregs=no%appl -erroff=E_TOKENLESS_MACRO,E_NONPORTABLE_BIT_FIELD_TYPE   -version-info 12:0:8     -export-symbols-regex '^curl_.*'  -lssl -lcrypto -lssl -lcrypto -lsocket -lnsl -ldl -lldap -lz -lrt -lsocket -lnsl -L/opt/sn/lib -L/opt/sn/lib/64 -R/opt/sn/lib:/opt/sn/lib/64 -L/usr/sfw/lib -o libcurl.la -rpath /opt/sn/lib libcurl_la-altsvc.lo libcurl_la-amigaos.lo  libcurl_la-asyn-ares.lo libcurl_la-asyn-thread.lo  libcurl_la-base64.lo libcurl_la-bufq.lo libcurl_la-bufref.lo  libcurl_la-c-hyper.lo libcurl_la-cf-h1-proxy.lo  libcurl_la-cf-h2-proxy.lo libcurl_la-cf-haproxy.lo  libcurl_la-cf-https-connect.lo libcurl_la-cf-socket.lo  libcurl_la-cfilters.lo libcurl_la-conncache.lo  libcurl_la-connect.lo libcurl_la-content_encoding.lo  libcurl_la-cookie.lo libcurl_la-curl_addrinfo.lo  libcurl_la-curl_des.lo libcurl_la-curl_endian.lo  libcurl_la-curl_fnmatch.lo libcurl_la-curl_get_line.lo  libcurl_la-curl_gethostname.lo libcurl_la-curl_gssapi.lo  libcurl_la-curl_memrchr.lo libcurl_la-curl_multibyte.lo  libcurl_la-curl_ntlm_core.lo libcurl_la-curl_ntlm_wb.lo  <snip>

libtool: link: echo "local: *; };" >> .libs/libcurl.so.4.8.0.exp
libtool: link:  cc -G -M .libs/libcurl.so.4.8.0.exp -h libcurl.so.4 -o .libs/libcurl.so.4.8.0  .libs/libcurl_la-altsvc.o .libs/libcurl_la-amigaos.o .libs/libcurl_la-asyn-ares.o .libs/libcurl_la-asyn-thread.o .libs
/libcurl_la-base64.o .libs/libcurl_la-bufq.o .libs/libcurl_la-bufref.o .libs/libcurl_la-c-hyper.o .libs/libcurl_la-cf-h1-proxy.o .libs/libcurl_la-cf-h2-proxy.o .libs/libcurl_la-cf-haproxy.o .libs/libcurl_la-cf-htt
ps-connect.o .libs/libcurl_la-cf-socket.o .libs/libcurl_la-cfilters.o .libs/libcurl_la-conncache.o .libs/libcurl_la-connect.o .libs/libcurl_la-content_encoding.o .libs/libcurl_la-cookie.o .libs/libcurl_la-curl_add
rinfo.o .libs/libcurl_la-curl_des.o .libs/libcurl_la-curl_endian.o .libs/libcurl_la-curl_fnmatch.o .libs/libcurl_la-curl_get_line.o .libs/libcurl_la-curl_gethostname.o .libs/libcurl_la-curl_gssapi.o .libs/libcurl_
la-curl_memrchr.o .libs/libcurl_la-curl_multibyte.o .libs/libcurl_la-curl_ntlm_core.o .libs/libcurl_la-curl_ntlm_wb.o .libs/libcurl_la-curl_path.o .libs/libcurl_la-curl_range.o .libs/libcurl_la-curl_rtmp.o .libs/l
ibcurl_la-curl_sasl.o .libs/libcurl_la-curl_sha512_256.o .libs/libcurl_la-curl_sspi.o .libs/libcurl_la-curl_threads.o .libs/libcurl_la-curl_trc.o .libs/libcurl_la-cw-out.o .libs/libcurl_la-dict.o .libs/libcurl_la-
doh.o .libs/libcurl_la-dynbuf.o .libs/libcurl_la-dynhds.o .libs/libcurl_la-easy.o .libs/libcurl_la-easygetopt.o .libs/libcurl_la-easyoptions.o .libs/libcurl_la-escape.o .libs/libcurl_la-file.o <snip>  -R/opt/sn/lib:/opt/sn/lib/64 -lssl -lcrypto -ldl -lldap -lz -lrt -lsocket -lnsl -L/opt/sn/lib -L/opt/sn/lib/64 -L/usr/sfw/lib -lc  -xtarget
=generic64 -xarch=generic64  
ld: fatal: library -lssl: not found
ld: fatal: library -lcrypto: not found
ld: fatal: File processing errors. No output written to .libs/libcurl.so.4.8.0
smake: *** Code 1 (Not owner) from command line for target 'libcurl.la'.
smake: Couldn't make 'all-am'.
smake: Leaving  '/opt/schily/bin/smake'[2] from directory '/opt/sn/build/curl-8.7.1.002/lib'
smake: Default commandline target: 'all-am'
smake: Doing                       exit(1)
...

The issue is that the -L options must come before the -l... options. No matter what I did (e.g. putting `-l ...- in LDFLAGS) it always produced the wrong order of arguments.

I expected the following

I expect the arguments to be supplied in the correct order. Or is there a better way to supply these options to the configure script. I've never had these issues with the curl configure script before.

curl/libcurl version

8.7.1 tarball fetched from https://curl.se/download.html.

operating system

Rather an old and strange system:

indium% uname -a
SunOS indium 5.11 snv_34 sun4u sparc SUNW,Ultra-60
indium% cc -V
cc: Sun C 5.7 Patch 117836-03 2005/05/11
usage: cc [ options] files.  Use 'cc -flags' for details
indium% openssl --version 
OpenSSL 3.2.1 30 Jan 2024 (Library: OpenSSL 3.2.1 30 Jan 2024)
indium% 
@bagder bagder added the build label Apr 8, 2024
@bagder
Copy link
Member

bagder commented Apr 8, 2024

Notice the funny grep: illegal option -- E on this system :-)

grep -E is POSIX so helps us emphasize the ancient nature of your target.

cc: Sun C 5.7 Patch 117836-03 2005/05/11

About nineteen years old. I would recommend you build a modern gcc version to build modern software with. It would probably make things easier.

I don't know why libtool + this linker get into this problem, but I personally also don't feel too inclined to work on this issue for just a single dinosaur. I could consider doing it as a paid assignment.

@vszakats
Copy link
Member

vszakats commented Apr 8, 2024

The issue is that the -L options must come before the -l... options. No matter what I did (e.g. putting `-l ...- in LDFLAGS) it always produced the wrong order of arguments.

This seems to confirm our suspicion that this Solaris linker (with positional -L and -l) + autotools / libtool (which isn't aware of this) are incompatible.

Here's a possible workaround:
#12824 (comment)

@herrhotzenplotz
Copy link
Author

Notice the funny grep: illegal option -- E on this system :-)

grep -E is POSIX so helps us emphasize the ancient nature of your target.

I am fully aware of this as I looked it up when I saw it printing this error.

cc: Sun C 5.7 Patch 117836-03 2005/05/11

About nineteen years old. I would recommend you build a modern gcc version to build modern software with. It would probably make things easier.

I am definitely going to build a newer compiler for this box. However, the linker won't change. The thing is that the compile itself went through cleanly, just the link stage is borked. I have no idea whether a newer compiler would change this (unless it is intelligent enought to sort the arguments accordingly when invoking the linker).

I don't know why libtool + this linker get into this problem, but I personally also don't feel too inclined to work on this issue for just a single dinosaur. I could consider doing it as a paid assignment.

Nah, don't worry. This is merely for software portability testing purposes. I simply wanted to report what I found in case someone else also stubles across this issue.

The issue is that the -L options must come before the -l... options. No matter what I did (e.g. putting `-l ...- in LDFLAGS) it always produced the wrong order of arguments.

This seems to confirm our suspicion that this Solaris linker (with positional -L and -l) + autotools / libtool (which isn't aware of this) are incompatible.

Here's a possible workaround: #12824 (comment)

Thank you! I will give this a try.

@herrhotzenplotz
Copy link
Author

This worked: #12824 (comment)

Set CURL_LDFLAGS_LIB="-L/opt/sn/lib -L/opt/sn/lib/64 -R/opt/sn/lib:/opt/lib/64" at compile time and it links successfully.

Thank you for the input.

@alanc
Copy link

alanc commented Apr 9, 2024

Also note that snv_34 indicates an early development build from 2006 of what would eventually be released as Solaris 11.0 over five years later and was never an officially supported OS, but was made available via the OpenSolaris project. (The current Solaris linker, like classic Unix linkers, still requires the -L flag to specify a library path come before the -l flag to use a library from that path, but the GNU autotools and GNU make seem to get this right when we build curl for modern Solaris.)

@bagder
Copy link
Member

bagder commented Apr 11, 2024

As there is a work-around and this is a very old target, I don't think this is even necessary to document. Closing.

@bagder bagder closed this as completed Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants