Skip to content

Conversation

dcbaker
Copy link
Member

@dcbaker dcbaker commented Jul 25, 2022

Apple, for some reason, decided that ranlib should not, by default, include extern'd variables in the symbol table when running ar with the -s option (run ranlib). So we must additionally call ranlib -c $out when linking a static archive, so that behavior is consistant between the Apple archiver and every other archvier other (including llvm-ar).

Incidently we never caught this because we have code to specifically chose llvm-ar when using any variaty of clang if it's available, and apple's clang is a variety of clang, and we install llvm for running llvm tests. Because of that I've modifed a test for apple that forces the use of the ar archiver, even when llvm-ar or gcc-ar are installed, and don't have this behavior.

Which is old and annoying and doesn't expose global symbols by default,
so we need a work around.

see: mesonbuild#10587
see: https://lists.gnu.org/archive/html/libtool/2002-07/msg00025.html
@dcbaker dcbaker requested a review from jpakkane as a code owner July 25, 2022 17:28
@dcbaker dcbaker force-pushed the submit/macos-call-ranlib branch from 9da65d7 to 5f91646 Compare July 25, 2022 17:29
@lgtm-com
Copy link

lgtm-com bot commented Jul 25, 2022

This pull request introduces 2 alerts when merging 5f91646 into ec388fe - view on LGTM.com

new alerts:

  • 1 for Unused local variable
  • 1 for Module is imported with 'import' and 'import from'

Apple's AR is old, and doesn't add externed symbols to the symbol table,
instead relying on the user calling ranlib with -c. We need to do that
for the user
@codecov
Copy link

codecov bot commented Jul 25, 2022

Codecov Report

Merging #10628 (6003618) into master (ec388fe) will decrease coverage by 10.77%.
The diff coverage is n/a.

❗ Current head 6003618 differs from pull request most recent head 87a36cd. Consider uploading reports for the commit 87a36cd to get more accurate results

@@             Coverage Diff             @@
##           master   #10628       +/-   ##
===========================================
- Coverage   68.83%   58.05%   -10.78%     
===========================================
  Files         406      203      -203     
  Lines       88038    44002    -44036     
  Branches    19550     9612     -9938     
===========================================
- Hits        60598    25547    -35051     
+ Misses      22868    16185     -6683     
+ Partials     4572     2270     -2302     
Impacted Files Coverage Δ
scripts/run_tool.py 0.00% <0.00%> (-100.00%) ⬇️
scripts/clangtidy.py 0.00% <0.00%> (-93.34%) ⬇️
modules/unstable_icestorm.py 0.00% <0.00%> (-91.67%) ⬇️
modules/unstable_cuda.py 0.00% <0.00%> (-72.64%) ⬇️
scripts/uninstall.py 0.00% <0.00%> (-71.88%) ⬇️
mconf.py 14.51% <0.00%> (-70.97%) ⬇️
templates/cstemplates.py 35.48% <0.00%> (-64.52%) ⬇️
scripts/coverage.py 0.00% <0.00%> (-64.36%) ⬇️
ast/introspection.py 15.25% <0.00%> (-63.56%) ⬇️
templates/javatemplates.py 36.66% <0.00%> (-63.34%) ⬇️
... and 305 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec388fe...87a36cd. Read the comment docs.

This forces the use of the Apple archiver, since that archiver doesn't
add extern'd variables to the symbol table automatically, and instead
requires that ranlib be used. A native file is used to ensure that
Apple's ar is used even in the presence of llvm or gcc in the path with
their superior archivers.

Co-authored-by: Dylan Baker <dylan@pnwbakers.com>
@dcbaker dcbaker force-pushed the submit/macos-call-ranlib branch from b1d1b23 to 87a36cd Compare July 25, 2022 19:58
@dcbaker dcbaker merged commit d285be7 into mesonbuild:master Jul 25, 2022
@dcbaker dcbaker deleted the submit/macos-call-ranlib branch July 25, 2022 22:37
@dcbaker
Copy link
Member Author

dcbaker commented Jul 25, 2022

@nirbheek this should get backported

@dcbaker dcbaker added this to the 0.63.1 milestone Jul 26, 2022
@eli-schwartz
Copy link
Member

eli-schwartz commented Aug 29, 2022

This broke other things, and was fixed in #10699

That in turn broke #10745 which we still don't have a fix for.

@nirbheek We should revert this backport for 0.63.2, I think, and let things settle in git master.

nirbheek added a commit that referenced this pull request Sep 2, 2022
As per #10628 (comment)
the real fix will be in 0.64.

This reverts commits:

Revert "linkers: Add a representation for the Apple AR Linker"
ee16f01.

Revert "backends/ninja: run `ranlib -c $out` when using the apple ar"
77e589c.

Revert "tests: Test extern'd globals on MacOS with the Apple Archiver"
bcb382b.
eli-schwartz added a commit to eli-schwartz/meson that referenced this pull request Nov 1, 2022
This reverts commit d285be7.

This is part of mesonbuild#10628 and needs to be reverted, as it breaks other
things.

See mesonbuild#10628 (comment)
eli-schwartz added a commit to eli-schwartz/meson that referenced this pull request Nov 1, 2022
This reverts commit bdc6f24.

This is part of mesonbuild#10628 and needs to be reverted, as it breaks other
things.

See mesonbuild#10628 (comment)
xclaesse pushed a commit to xclaesse/meson that referenced this pull request Jul 5, 2023
This is a regression test for:
mesonbuild#11165.

The test was initially merged as part of:
mesonbuild#10628, but had to be reverted.

A second attempt at fixing the root cause also had to be reverted:
mesonbuild#10699.

A 3rd attempt got merged but missed this unit test:
mesonbuild#11742.

Co-authored-by: Dylan Baker <dylan@pnwbakers.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants