]> git.lizzy.rs Git - rust.git/commit
Store metadata separately in rlib files
authorAlex Crichton <alex@alexcrichton.com>
Wed, 4 Dec 2013 01:41:01 +0000 (17:41 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 9 Dec 2013 16:25:58 +0000 (08:25 -0800)
commit52b835c5e7a68b32a8f0532f178c150d09be200d
tree8bb348671eb0bc046cfeb3d233e54003c155b6e8
parent4e0cb316fc980f00e1b74f3fdb7a842b540be280
Store metadata separately in rlib files

Right now whenever an rlib file is linked against, all of the metadata from the
rlib is pulled in to the final staticlib or binary. The reason for this is that
the metadata is currently stored in a section of the object file. Note that this
is intentional for dynamic libraries in order to distribute metadata bundled
with static libraries.

This commit alters the situation for rlib libraries to instead store the
metadata in a separate file in the archive. In doing so, when the archive is
passed to the linker, none of the metadata will get pulled into the result
executable. Furthermore, the metadata file is skipped when assembling rlibs into
an archive.

The snag in this implementation comes with multiple output formats. When
generating a dylib, the metadata needs to be in the object file, but when
generating an rlib this needs to be separate. In order to accomplish this, the
metadata variable is inserted into an entirely separate LLVM Module which is
then codegen'd into a different location (foo.metadata.o). This is then linked
into dynamic libraries and silently ignored for rlib files.

While changing how metadata is inserted into archives, I have also stopped
compressing metadata when inserted into rlib files. We have wanted to stop
compressing metadata, but the sections it creates in object file sections are
apparently too large. Thankfully if it's just an arbitrary file it doesn't
matter how large it is.

I have seen massive reductions in executable sizes, as well as staticlib output
sizes (to confirm that this is all working).
src/librustc/back/archive.rs
src/librustc/back/link.rs
src/librustc/driver/driver.rs
src/librustc/metadata/encoder.rs
src/librustc/metadata/loader.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/trans/context.rs