Skip to content

Read and write dylib metadata #435

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

Merged
merged 10 commits into from
Jun 11, 2019
Merged

Read and write dylib metadata #435

merged 10 commits into from
Jun 11, 2019

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Mar 27, 2019

@m4b I (mis)used Decl::debug_section() to add a .rustc section. Is this supported or may future versions of faerie break this?

Fixes #412

@bjorn3 bjorn3 added this to the MVP milestone Mar 27, 2019
src/metadata.rs Outdated
DeflateEncoder::new(&mut compressed, Compression::fast())
.write_all(&metadata.raw_data).unwrap();

artifact.declare_with(".rustc", faerie::Decl::debug_section(), compressed).unwrap();
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 used it here.

@bjorn3 bjorn3 force-pushed the write_dylib_metadata branch from 7f7343d to b802e9d Compare March 27, 2019 18:46
@philipc
Copy link
Contributor

philipc commented Mar 27, 2019

For MachO, Decl::debug_section() is placed in the __DWARF segment.

@m4b
Copy link

m4b commented Mar 28, 2019

Yea we need to add explicit section ability, it’s unfortunately not implemented yet to my knowledge. I don’t think it will be a lot of work since we already write out sections so the machinery is there. Someone just needs to add the api :)

@bjorn3 would you like to try out a PR? :D

@bjorn3
Copy link
Member Author

bjorn3 commented Mar 28, 2019

For MachO, Decl::debug_section() is placed in the __DWARF segment.

cg_llvm puts it in __DATA. :) It also explains the macOS travis failure.

@bjorn3 would you like to try out a PR? :D

Sure

@bjorn3
Copy link
Member Author

bjorn3 commented Mar 30, 2019

Blocked on rust-lang/rust#59564 to stop the duplication of the linker code between cg_clif and cg_llvm.

@bjorn3 bjorn3 force-pushed the write_dylib_metadata branch from 8d590bc to fc94af2 Compare April 4, 2019 18:43
@bjorn3 bjorn3 force-pushed the write_dylib_metadata branch from fc94af2 to 5240aca Compare April 15, 2019 14:57
@bjorn3 bjorn3 force-pushed the write_dylib_metadata branch from 5240aca to ba1659d Compare April 27, 2019 16:59
@bjorn3
Copy link
Member Author

bjorn3 commented May 4, 2019

The .rustc section is somehow discarded when linking the metadata module into the dylib on macOS. @m4b do you have any clue how that could be?

@bjorn3 bjorn3 force-pushed the write_dylib_metadata branch 2 times, most recently from acb414d to d59234b Compare May 4, 2019 15:06
@bjorn3 bjorn3 force-pushed the write_dylib_metadata branch from d59234b to a6821a2 Compare May 25, 2019 12:12
@bjorn3
Copy link
Member Author

bjorn3 commented May 25, 2019

Seems like there should be a symbol names like _rust_metadata_rust_out_8787f43e282added376259c1adb08b80 in the .rustc section:

https://github.com/rust-lang/rust/blob/767f59462663fbc55a69d39fc5e1f7f83b6fb37d/src/librustc_codegen_llvm/base.rs#L61

@m4b
Copy link

m4b commented May 25, 2019

@bjorn3 Sorry missed your ping, did your recent PR to faerie resolve the issue about dylibs having sections discarded ?

@bjorn3
Copy link
Member Author

bjorn3 commented May 25, 2019

Sorry missed your ping

No problem.

did your recent PR to faerie resolve the issue about dylibs having sections discarded ?

No, cg_llvm seems to also create a symbol referencing the metadata. Doing that here too may solve the problem. Unfortunately faerie doesnt support symbols in custom sections.

@m4b
Copy link

m4b commented May 25, 2019

Hmm, I thought you could create a symbol referencing a section; @pchickey any suggestion here?
In the meantime, @bjorn3 could you just add a manual line in faerie creating the symbol referencing your section metadata to confirm it's the issue?

@bjorn3 bjorn3 force-pushed the write_dylib_metadata branch from 909acc6 to e242671 Compare May 26, 2019 08:22
@bjorn3
Copy link
Member Author

bjorn3 commented May 26, 2019

Yup adding a global symbol pointing to the start of the section fixes it:

Sections:
Idx Name          Size      Address          Type
  0 __text        00000679 0000000000000910 TEXT 
  1 __stubs       00000006 0000000000000f8a TEXT 
  2 __stub_helper 0000001a 0000000000000f90 TEXT 
  3 __unwind_info 00000048 0000000000000fac DATA 
  4 __nl_symbol_ptr 00000010 0000000000001000 DATA 
  5 __la_symbol_ptr 00000008 0000000000001010 DATA 
  6 __data        00000541 0000000000001018 DATA 
  7 .rustc        0000491d 000000000000155a DATA 

@bjorn3
Copy link
Member Author

bjorn3 commented May 26, 2019

In what way should faerie expose this? Specify the section a normal decl is put in? Or specify the symbols for a section decl?

@bjorn3
Copy link
Member Author

bjorn3 commented May 30, 2019

Gentle ping @m4b

@m4b
Copy link

m4b commented May 31, 2019

@bjorn3 given your results, it seems reasonable for the user to specify symbol + data + optional section, and create the section if it isn’t there ? I suspect it’s going to complicate some of the setup logic, but maybe not.

Will require another PR :( is this blocking you right now ?

@bjorn3
Copy link
Member Author

bjorn3 commented May 31, 2019

Did you see m4b/faerie#83? I chose the "Specify the symbols for a section decl?" route. This is not really blocking me.

@bjorn3 bjorn3 force-pushed the write_dylib_metadata branch from 949086b to 07bb89a Compare June 11, 2019 14:58
@bjorn3
Copy link
Member Author

bjorn3 commented Jun 11, 2019

This has a patch section, because m4b/faerie#83 and gimli-rs/object#109 haven't landed in a version published on crates.io.

@bjorn3 bjorn3 merged commit db85194 into master Jun 11, 2019
@bjorn3 bjorn3 deleted the write_dylib_metadata branch June 11, 2019 15:22
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.

Implement dylib metadata store and load
3 participants