Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Use philipc's object::write to emit object files - #271

Closed
pchickey wants to merge 2 commits into
masterfrom
pch/philipc_object
Closed

pchickey wants to merge 2 commits into
masterfrom
pch/philipc_object

Conversation

@pchickey

Copy link
Copy Markdown
Contributor

No description provided.

@jedisct1

jedisct1 commented Aug 22, 2019 •

Copy link
Copy Markdown
Contributor

This is producing an invalid object on MacOS:

ld: illegal text-relocation to 'guest_table_0' in 
    /var/folders/gq/pbvv220x79156lw2f_f22r5w0000gn/T/lucetcfv14BM/tmp.o 
    from 'guest_table_0'

How to reproduce

int main(void)
{
    return 0;
}
clang --target=wasm32-wasi --sysroot /opt/wasi-libc -O2 -s -o a.wasm a.c

lucetc-wasi a.wasm

WASM file and resulting object files:

a.wasm.gz
a.obj.gz

@philipc

philipc commented Aug 23, 2019

Copy link
Copy Markdown

Looks like I moved too much into __TEXT/__const (it used to all be in __DATA/__data). I've added gimli-rs/object@1f8a490 which should let us use __DATA/__const instead for const data that has relocations. This will require a small change in cranelift-object too.

@jedisct1

jedisct1 commented Sep 4, 2019

Copy link
Copy Markdown
Contributor

Pretty ugly, but the following diff over object rev a2758023ea001c5e9fba79ebc476bd81b0bda8fa seems to help lucetc build valid Mach-O files.

https://gist.github.com/4eccc9f79d8db408e1c1717a4d446d49

BTW, that file can come in handy: https://opensource.apple.com/source/ld64/ld64-128.2/src/ld/parsers/macho_relocatable_file.cpp.auto.html

@philipc

philipc commented Sep 4, 2019 •

Copy link
Copy Markdown

@jedisct1 Thanks for figuring out those fixes!

Can you explain more about the underscore prefix, or point to some documentation about it? I see that faerie writes the underscore for every symbol, but you've only added for globals.

I might have to come up with a way of making the underscore an option in add_symbol, since always adding it during writing is going to break the objcopy round trip (unless I remove it again when reading?).

@jedisct1

jedisct1 commented Sep 5, 2019

Copy link
Copy Markdown
Contributor

Hi @philipc ,

The Mach-O documentation says:

The name of a symbol representing a function that conforms to standard C calling conventions is the name of the function with an underscore prefix. Thus, the name of the symbol representing the function main would be _main.

So I guess it indeed should also be applied to non-exported functions.

COFF symbols also need leading underscores.

@jedisct1

jedisct1 commented Sep 5, 2019

Copy link
Copy Markdown
Contributor

I don't think any other calling convention has even been used on MacOS.

LLVM skips leading underscores unconditionally on Mach-O files.

So maybe it would make sense to heave the read interface remove these underscores, so we have symmetry between the read and write interfaces.

@philipc

philipc commented Sep 8, 2019

Copy link
Copy Markdown

I've opened gimli-rs/object#127 to fix those issues, if you could review that.

I chosen to make the mangling optional, and disable this for objcopy. That LLVM link is only for the symbolizer, which is a bit higher level than the API that the object crate wants to provide. I've based this on this LLVM code.

@pchickey

Copy link
Copy Markdown
Contributor Author

Closing in favor of #295

@pchickey pchickey closed this Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants