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

autotools: accept linker flags via CURL_LDFLAGS_{LIB,BIN} #12312

Closed
wants to merge 2 commits into from

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Nov 13, 2023

To allow passing LDFLAGS specific to libcurl (CURL_LDFLAGS_LIB) and
curl tool (CURL_LDFLAGS_BIN).

This makes it possible to build libcurl and curl with a single
invocation with lib- and tool-specific custom linker flags.

Such flag can be enabling .map files, a .def file for libcurl DLL,
controlling static/shared, incl. requesting a static curl tool (with
-static-libtool-libs) while building both shared and static libcurl.

curl-for-win uses the above and some more.

These options are already supported in Makefile.mk. CMake has built-in
variables for this.

Closes #12312

autotools passes `LDFLAGS` automatically to the linker command. curl's
`lib/Makefile.am` customizes libcurl linker flags. In that
customization, it added `LDFLAGS` to the custom options. This resulted
in passing `LDFLAGS` _twice_ to the `libtool` command.

Most of the time this is benign, but some `LDFLAGS` options can break
the build when passed twice. One such example is passing `.o` files,
e.g. `crt*.o` files necessary when customizing the C runtime, e.g. for
MUSL builds.

Passing them twice resulted in duplicate symbol errors:
```
libtool: link:  clang-15 --target=aarch64-unknown-linux-musl [...] /usr/lib/aarch64-linux-musl/crt1.o [...] /usr/lib/aarch64-linux-musl/crt1.o [...]
ld.lld-15: error: duplicate symbol: _start
>>> defined at crt1.c
>>>            /usr/lib/aarch64-linux-musl/crt1.o:(.text+0x0)
>>> defined at crt1.c
>>>            /usr/lib/aarch64-linux-musl/crt1.o:(.text+0x0)
[...]
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

This patch deletes `LDFLAGS` from our customized options, leaving a
single copy of them as passed by autotools automatically.

This behaviour came with commit 1a59319
(2013-07-23) as a fix for bug https://curl.haxx.se/bug/view.cgi?id=1217.
The patch was a works-for-me hack that ended up merged in curl:
https://sourceforge.net/p/curl/bugs/1217/#06ef
With the root cause remaining unclear. Perhaps the SUNPro 12 linker was
sensitive to `-L` `-l` order, requiring `-L` first? This would be
unusual and might suggest a bug in either the linker or in `libtool`.
The curl build does indeed pass the list of detected libs via its own
`LIBCURL_LIBS` variable, which ends up before `LDFLAGS` on the `libtool`
command line, but it would seem to be the job of `libtool` to ensure
that even a buggy/peculiar linker gets the options in the order it's
expecting it. Especially because autotools passes `LDFLAGS` last, making
it hardly possibly to pass anything after it. Perhaps in the 10 years
since this issue, this already got a fix upstream.

IMO passing `LDFLAGS` twice to fix the above is a nuclear option with
unintended side-effects.

Closes #xxxxx
…BIN`

To allow passing `LDFLAGS` specific to libcurl (`CURL_LDFLAGS_LIB`)
and curl tool (`CURL_LDFLAGS_BIN`).

This makes it possible to build libcurl and curl with a single
invocation with lib- and tool-specific custom linker flags.

Such flag can be enabling `.map` files, a `.def` file for libcurl DLL,
controlling static/shared, incl. requesting a static curl tool (with
`-static-libtool-libs`) while building both shared and static libcurl.

curl-for-win uses the above and some more.

Closes #xxxxx
@vszakats vszakats added the build label Nov 13, 2023
@vszakats vszakats changed the title autotools: accept linker flags via CURL_LDFLAGS_LIB, CURL_LDFLAGS_BIN autotools: accept linker flags via CURL_LDFLAGS_LIB, CURL_LDFLAGS_BIN Nov 13, 2023
@vszakats vszakats changed the title autotools: accept linker flags via CURL_LDFLAGS_LIB, CURL_LDFLAGS_BIN autotools: accept linker flags via CURL_LDFLAGS_{LIB,BIN} Nov 13, 2023
vszakats added a commit to curl/curl-for-win that referenced this pull request Nov 13, 2023
@vszakats vszakats closed this in b365a34 Nov 14, 2023
@vszakats vszakats deleted the autotools-lib-bin-ldflags branch November 14, 2023 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

1 participant