-
Notifications
You must be signed in to change notification settings - Fork 26
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
Support emitting more than 0x10000 functions in a file #76
Comments
Haha, awesome bug find! :) If that isn't the case then:
This could be straightforward, or more difficult, not sure yet; I'm guessing harder, since I think we assume function sections throughout, but like I said, not exactly sure. Anyway, yes it's something we should fix (or at least fail in a controller manner instead of overflow bugs causing mayhem in release code), but it is slightly niche, since i think it's somewhat unusual for a single compilation unit to have 65k functions. Anyway, great find though! |
@m4b Whoa, thank you so much for the super fast response during a holiday! I'm currently trying to compile a really large WASM file using Fastly's Lucet, which emits the entire translated .wasm as one single .o file - that's how I ran into this. You're probably right about the extra sections magic value. (Edit: see http://man7.org/linux/man-pages/man5/elf.5.html and search for SHN_LORESERVE) Clang can emit a .o file with all sections when I compile a .c file with 0x10000 functions. readelf correctly finds all 65545 sections in the result:
|
@m4b According to https://docs.oracle.com/cd/E37838_01/pdf/E36783.pdf p373, to support more than SHN_LORESERVE (0xff00) sections:
I can try doing the first two, but the last seems complicated. |
That's a start. We should also update phdrs, and strtab with same logic, it looks like it just places all the real values in the first null entry of the section table headers. Will have to investigate |
@m4b I tried doing something similar and hit this assert: https://github.com/m4b/faerie/blob/master/src/elf.rs#L115 So it looks like we do need the extended symbol table. I'll try to look into this tomorrow, but I'm not too familiar with how to generate ELF. Thank you so much! |
@m4b I tried adding a sections indices table and it just completely broke readelf and llvm-objdump: https://github.com/swiftwasm/faerie/tree/i-cant-implement-shndxr So I guess I don't know how to implement this - is there any other ways I can help?
|
@zhuowei it's hard to see without a PR showing the diff, but it looks like you were close? As I think you've discovered, these kind of things are extremely brittle, and minor changes can make object file parsers explode :D On the other hand, it can be misleading, because with a minor change here or there, the whole thing might start working 😆 |
@m4b PR opened. This is my first time working with Rust code outside the Rust tutorial, and the ... third? time I ever tried to emit an ELF file, so I'm sorry in advance for the code. I suspect there's probably a cleaner way to generate the extra table. Thank you so much for your work on this project. Getting this to work is probably beyond my current abilities, so I'll really appreciate it if you can take a look at this issue. PS: for future reference: GitHub lets you open pull requests using other people's branches if you want a diff view. |
Well hey welcome ! :) thanks for the tip did not know could open PRs using other branches ! I’ll take a look soon and thanks for your work :) |
This was solved by #78 - closing. Thank you so much for fixing this! |
I tried to generate an ELF object with 65536 functions with faerie and received an integer overflow error in debug mode when faerie calculates the number of sections (src/elf.rs:571) In release mode, faerie simply generates an invalid .o file.
Is it possible for faerie to generate less ELF sections/avoid generating a separate section for each function, so it can generate larger files?
Test code and crash log:
The text was updated successfully, but these errors were encountered: