Bug 236365 - [CMake] REGRESSION(r288994): Setting multiple values in LDFLAGS causes incorrect linker detection
Summary: [CMake] REGRESSION(r288994): Setting multiple values in LDFLAGS causes incorr...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Adrian Perez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-02-09 07:21 PST by Adrian Perez
Modified: 2022-02-09 08:36 PST (History)
15 users (show)

See Also:


Attachments
Patch (2.21 KB, patch)
2022-02-09 07:33 PST, Adrian Perez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adrian Perez 2022-02-09 07:21:05 PST
After r288994, doing something like the following will cause the linker
to be wrongly identified:

  LDFLAGS='-Wl,-O1 -Wl,--as-needed' Tools/Scripts/build-webkit [...]

and CMake will print the following (it should read “BFD”):

  -- Linker variant in use: UNKNOWN
Comment 1 Adrian Perez 2022-02-09 07:26:51 PST
This is caused by CMake's execute_process() passing arguments verbatim
to the command without using the shell nor doing any splitting. Setting 
LDFLAGS='-Wl,-O1 -Wl,--as-needed' before running CMake results in the
variable CMAKE_EXE_LINKER_FLAGS having the literal value of LDFLAGS,
and then this:

  execute_process(
    COMMAND ${CMAKE_C_COMPILER} ${CMAKE_EXE_LINKER_FLAGS} -Wl,--version
    OUTPUT_VARIABLE LD_VERSION
    ERROR_QUIET
  )

Results in trying to executing (argument index in square brackets):

  [0]: cc
  [1]: -Wl,-O1 -Wl,--as-needed
  [2]: -Wl,--version

When what is needed is:

  [0]: cc
  [1]: -Wl,-O1
  [2]: -Wl,--as-needed
  [3]: -Wl,--version

I have a patch to fix the two usages of execute_process() introduced
in r288994 but we might want to audit all the callsites where this CMake
command is used to make sure no other similar problems lurk undiscovered.
Comment 2 Adrian Perez 2022-02-09 07:30:52 PST
Note that previous uses of execute_process() would hit the same
issue when setting LD/CC/CXX in the environment to some value that
includes spaces, so the following would fail even before the patch
from r288994:

  CC='ccache gcc' CXX='ccache g++' Tools/Scripts/build-webkit [...]

This explains why I have a vague memory of trying to use “ccache” by
adding it as prefix for the compiler command and it failed (of course
this is *not* the recommended way of using “ccache”, but the same issue
would break the build with any other similar compiler wrappers.)
Comment 3 Adrian Perez 2022-02-09 07:33:58 PST
Created attachment 451375 [details]
Patch
Comment 4 EWS 2022-02-09 08:35:47 PST
Committed r289473 (247016@main): <https://commits.webkit.org/247016@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 451375 [details].
Comment 5 Radar WebKit Bug Importer 2022-02-09 08:36:17 PST
<rdar://problem/88691618>