-
Notifications
You must be signed in to change notification settings - Fork 54
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
Crash when there are more than ten CODE resources when using a custom segmap #195
Comments
There seem to be two different places where ID numbers are assigned, and once there are ten segments the two algorithms don't match up. First, out << "\t.code" << id << " : {\n"; out << "\t\t__EH_FRAME_BEGIN__" << id << " = .;\n"; out << boost::replace_all_copy<string>(R"ld(
. = ALIGN(0x4);
FILL(0);
. += 32;
LONG(__EH_FRAME_BEGIN__@N@ - .);
)ld", "@N@", boost::lexical_cast<string>(id)); After the linker has run, its output is parsed in std::sort(codeSections.begin(), codeSections.end(),
[](shared_ptr<Section> a, shared_ptr<Section> b) { return a->name < b->name; }); I suspect this is where things go awry, since the sort order will be in lexical (alphabetical) order rather than in numerical order:
Finally, The simplest solution is probably to pad the IDs with a sufficient number of leading zeroes when inserting them into the linker script such that all of the IDs have the same width and will then sort correctly in a lexical sort:
Another solution could be to change the sort comparison function to one that performs natural order sorting. A third possibility would be not to assume that the segments are in any particular order and to extract the correct segment number by converting the string representation of the ID in the ELF file back into an integer and using that as the ID. |
I'm trying to understand how and why to use a custom segmap (#192) and in the process of investigating this I'm encountering a crash when a custom segmap results in there being more than ten
CODE
resources in the application.Almost minimal reproduction example: https://gist.github.com/ryandesign/1ad7e2e2f6cf967548928750d872e033
(It includes RetroConsole which is not necessary to demonstrate the problem but having more segments be non-empty makes the problem easier to see when looking at the resource sizes.)
The default segmap results in nine
CODE
resources and the app works fine:When I use a custom segmap that attempts to reproduce this default, I also get nine
CODE
resources (in a slightly different order) and the app works fine:When I add another segment (with nothing in it) the app still works fine:
When I add yet another segment (with nothing in it) you can tell by the
CODE
resource sizes that they contain the wrong data and the app crashes immediately on launch:For this last one, we also get
Invalid ref
errors when linking, like:Full build output is in the above gist URL.
The text was updated successfully, but these errors were encountered: