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

ar linker: generate thin archives for uninstalled static libraries #9294

Merged
merged 2 commits into from
Oct 10, 2021

Conversation

eli-schwartz
Copy link
Member

@eli-schwartz eli-schwartz commented Sep 23, 2021

Since they will never be used outside of the build directory, they do not need to literally contain the .o files, and references will be sufficient.

This covers a major use of object libraries, which is that the static library would potentially take up a lot of space by including another copy of every .o file.

Fixes #9292
Fixes #8057
Fixes #2129

@eli-schwartz eli-schwartz marked this pull request as draft September 23, 2021 23:51
return self.std_args
def get_std_link_args(self, is_thin: bool) -> T.List[str]:
# not supported by armar
# FIXME: osx ld rejects this: "file built for unknown-unsupported file format"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this OSX failure.

From https://github.com/eli-schwartz/meson/runs/3693121858

cc  -o prog prog.p/prog.c.o -Wl,-dead_strip_dylibs -Wl,-headerpad_max_install_names -Wl,-undefined,error libhelper.a
ld: warning: ignoring file libhelper.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x74 0x68 0x69 0x6E 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
Undefined symbols for architecture x86_64:
  "_func", referenced from:
      _main in prog.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@codecov
Copy link

codecov bot commented Sep 23, 2021

Codecov Report

Merging #9294 (ba432c8) into master (ba432c8) will not change coverage.
The diff coverage is n/a.

❗ Current head ba432c8 differs from pull request most recent head 0a3a9fa. Consider uploading reports for the commit 0a3a9fa to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##           master    #9294   +/-   ##
=======================================
  Coverage   67.29%   67.29%           
=======================================
  Files         394      394           
  Lines       85326    85326           
  Branches    17455    17455           
=======================================
  Hits        57421    57421           
  Misses      23229    23229           
  Partials     4676     4676           

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 ba432c8...0a3a9fa. Read the comment docs.

@jpakkane
Copy link
Member

Featurewise this is good, just have to ensure that it does not cause regressions for some use cases. (No, I don't know what those would be, just thinking out loud.)

@mesonbuild mesonbuild deleted a comment from lgtm-com bot Sep 24, 2021
Copy link
Member

@dcbaker dcbaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me to.

Copy link
Contributor

@keszybz keszybz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use a lot of convenience libraries for systemd, and this PR makes great improvements:

$ ls -l build{,-meson}/src/core/*.a              
-rw-r--r-- 1 zbyszek zbyszek 10208766 Oct  1 14:47 build/src/core/libcore.a
-rw-r--r-- 1 zbyszek zbyszek    29218 Oct  3 14:13 build-meson/src/core/libcore.a
$ ls -l build{,-meson}/src/basic/libbasic.a       
-rw-r--r-- 1 zbyszek zbyszek 3120020 Oct  1 14:46 build/src/basic/libbasic.a
-rw-r--r-- 1 zbyszek zbyszek   35110 Oct  3 14:12 build-meson/src/basic/libbasic.a

Me likes ;)

self.std_args = ['csr']
stdargs += 'D'
if '[T]' in stdo:
thinargs = 'T'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinargs += 'T' (for consistency)

Comment on lines +183 to +203
self.std_args = [stdargs]
self.std_thin_args = [stdargs + thinargs]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe write this as

self.std_args = ('csr' +
                         ('D' if '[D]' in stdo else ''))
self.std_thin_args = (self.std_args +
                                 ('T' if '[T]' in stdo else ''))

I think it's easier to read.

@eli-schwartz
Copy link
Member Author

Did some basic reorganization while I was at it, since I disliked having to use if self.id == 'ar' in there :/

@lgtm-com
Copy link

lgtm-com bot commented Oct 10, 2021

This pull request introduces 1 alert and fixes 2 when merging fb290f7 into ba432c8 - view on LGTM.com

new alerts:

  • 1 for Unused local variable

fixed alerts:

  • 2 for Missing call to `__init__` during object initialization

@eli-schwartz eli-schwartz force-pushed the ar-thin-archive branch 2 times, most recently from bd51e62 to ad3b2e7 Compare October 10, 2021 15:30
@eli-schwartz
Copy link
Member Author

Not a new alert, lol, just a moved one. Still, why not fix that too...

The `init__()` method basically existed solely to be overridden by every
derivative class. Better to use it only in the class that needs it.

This fixes several warnings, including missing calls to init because we
skipped ArLinker due to not wanting it... also get rid of a pointless
popen return code saved as pc, which we never checked.
@lgtm-com
Copy link

lgtm-com bot commented Oct 10, 2021

This pull request fixes 2 alerts when merging 795a4a4 into ba432c8 - view on LGTM.com

fixed alerts:

  • 2 for Missing call to `__init__` during object initialization

Since they will never be used outside of the build directory, they do
not need to literally contain the .o files, and references will be
sufficient.

This covers a major use of object libraries, which is that the static
library would potentially take up a lot of space by including another
copy of every .o file.

Fixes mesonbuild#9292
Fixes mesonbuild#8057
Fixes mesonbuild#2129
@eli-schwartz eli-schwartz marked this pull request as ready for review October 10, 2021 17:33
@eli-schwartz
Copy link
Member Author

This passed CI before I added release notes.

@eli-schwartz eli-schwartz merged commit 0a3a9fa into mesonbuild:master Oct 10, 2021
@eli-schwartz eli-schwartz deleted the ar-thin-archive branch October 10, 2021 17:34
@lgtm-com
Copy link

lgtm-com bot commented Oct 10, 2021

This pull request fixes 2 alerts when merging 0a3a9fa into ba432c8 - view on LGTM.com

fixed alerts:

  • 2 for Missing call to `__init__` during object initialization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants