Skip to content

add toolchain option to customize linker command that compiler should use + use correct compiler options for using mold with GCC (WIP)#4025

Draft
boegel wants to merge 4 commits intoeasybuilders:developfrom
boegel:linker_toolchain_opt
Draft

add toolchain option to customize linker command that compiler should use + use correct compiler options for using mold with GCC (WIP)#4025
boegel wants to merge 4 commits intoeasybuilders:developfrom
boegel:linker_toolchain_opt

Conversation

@boegel
Copy link
Copy Markdown
Member

@boegel boegel commented Jun 11, 2022

Usage to use mold as a linker:

toolchainopts = {'linker': 'mold'}

For non-GCC compilers (Clang, Intel) and GCC 12.1, this is equivalent with adding -fuse-ld=mold to $CFLAGS and friends.
For GCC < 12.1, this is equivalent to adding -B$EBROOTMOLD/libexec/mold to $CFLAGS and co.
See also classic way to use mold at https://github.com/rui314/mold#how-to-use.

Of course this also requires that mold is actually available, so it should be added as a build dependency (or be available system-wide).

Marked as WIP because:

  • these change broke one of the tests for some reason (to be figured out);
  • need to make sure that tests cover old/new GCC, Intel, Clang;
  • using this with Intel compilers doesn't actually seem to work; tested with GSL 2.7:
    $ ls software/GSL/*/bin/gsl-histogram | xargs readelf -p .comment | egrep '^File|mold'
    File: software/GSL/2.7-ClangGCC-13.0.1-11.2.0/bin/gsl-histogram
      [    53]  mold 1.2.1 (compatible with GNU ld)
    File: software/GSL/2.7-GCC-11.3.0/bin/gsl-histogram
      [    2c]  mold 1.2.1 (compatible with GNU ld)
    File: software/GSL/2.7-intel-compilers-2022.1.0/bin/gsl-histogram
    

@boegel boegel added this to the 4.x milestone Jun 11, 2022
@boegel boegel marked this pull request as draft June 11, 2022 09:40
@boegel boegel changed the title add toolchain option to customize linker command that compiler should use (WIP) add toolchain option to customize linker command that compiler should use + use correct compiler options for using mold with GCC (WIP) Jun 17, 2022
@boegel boegel force-pushed the linker_toolchain_opt branch from efc8e8d to ffe7a92 Compare June 17, 2022 14:49
@easybuilders easybuilders deleted a comment from boegelbot Jun 17, 2022
@boegel boegel force-pushed the linker_toolchain_opt branch from ffe7a92 to 3609e55 Compare June 17, 2022 14:50
@easybuilders easybuilders deleted a comment from boegelbot Jun 17, 2022
@boegel
Copy link
Copy Markdown
Member Author

boegel commented Jun 22, 2022

Based on https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compiler-reference/compiler-options/linking-or-linker-options/fuse-ld.html, the -fuse-ld compiler option only accepts bfd or gold, so -fuse-ld=mold doesn't work as expected.
Rather than producing an error when passing an unsupported value, it seems that the Intel compiler just silently ignores that option and continues with using its default linker instead. So we should probably resort to also using the -B workaround for the Intel compiler.

@rui314 Have you ever tested mold with the Intel compilers?

@rui314
Copy link
Copy Markdown

rui314 commented Jun 23, 2022

@boegel A few bugs have been filed to make mold work with ICC. We fixed them, and the bug reporters seemed happy, so I believe it works with ICC. But I haven't tried it myself.

@boegel
Copy link
Copy Markdown
Member Author

boegel commented Jun 23, 2022

@rui314 Is it correct that you need to use the -B option to make ICC use mold as linker (as opposed to -fuse-ld=mold)?
If so, I'll open a pull request to update mold's README file to mention that...

@rui314
Copy link
Copy Markdown

rui314 commented Jun 23, 2022

@boegel I don't actually know. If icc doesn't take -fuse-ld=mold, then the answer is probably yes though.

@boegel
Copy link
Copy Markdown
Member Author

boegel commented Jun 23, 2022

@boegel I don't actually know. If icc doesn't take -fuse-ld=mold, then the answer is probably yes though.

Well, it accepts the option, but then silently doesn't use mold at all (based on output of readelf -p .comment on the binary)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants