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

How to handle DW_GNU_EH_PE_absptr in unwind tables? #415

Open
bjorn3 opened this issue Dec 28, 2021 · 3 comments
Open

How to handle DW_GNU_EH_PE_absptr in unwind tables? #415

bjorn3 opened this issue Dec 28, 2021 · 3 comments

Comments

@bjorn3
Copy link
Contributor

bjorn3 commented Dec 28, 2021

On macOS LLVM emits __TEXT,__eh_frame sections with the DW_GNU_EH_PE_pcrel + DW_GNU_EH_PE_absptr pointer encoding and without relocations. This means that the pointers are encoded as the difference between the target address and the pointer address. There currently isn't any way to apply the relocations of these pointers while writing the object files as required by the macOS linker (it simply ignores relocations to this section when rewriting it during linking). It isn't possible to get the address of the __eh_frame and __text sections before emitting the object file to manually relocate it before handing it over to object. How should this best be handled?

@philipc
Copy link
Contributor

philipc commented Dec 28, 2021

Can you provide an example of an object emitted by LLVM?

@bjorn3
Copy link
Contributor Author

bjorn3 commented Dec 28, 2021

rust_out.rust_out.3a1fbbbh-cgu.0.rcgu.o.gz (had to gzip it for github to accept it.) Produced using echo '#![feature(no_core, lang_items)] #![no_core] #[lang = "sized"] trait Sized {} extern "Rust" { fn foo(); } pub unsafe fn bar() { foo(); }' | RUSTC_BOOTSTRAP=1 rustc --target x86_64-apple-darwin - -Cembed-bitcode=no -Csave-temps --crate-type lib. Using unstable features to produce an as smal as possible object file and to not have to install the standard library for macOS.

@philipc
Copy link
Contributor

philipc commented Dec 29, 2021

We need to apply these relocations during writing in write::Object::write_macho.

I'm not sure if this should be done automatically (based on section name or a new section kind), or requested by the user (flag for section or target symbol or individual relocation). The implementation in LLVM seems to handle this by setting the relocation target symbol to a temporary symbol that isn't emitted.

Will the __eh_frame section ever have other relocations that shouldn't be applied before writing? It looks like LSDA pointers need to be handled the same way, but I'm not sure about personality functions.

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

No branches or pull requests

2 participants