Fix Error.mapM returning reversed list #6
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is (hopefully) the last episode of the long list of patches trying to fix
the reversed lists issues. I originally started to try to fix in 1, but I
realized that the fix is incorrect.
My previous patch changed how
read_elf{32,64}_section_header_table'returnedits output: instead of putting the newly parsed element at the head of the list,
it appends it at the end. However this is wrong: the function first parses a
header, and then parses the remaining headers recursively. This means the
parsed element must become the head of the returned list.
I then tried to pin down the real issue from where I noticed it, in
elf_memory_image_of_elf64_file. In this function the sections are reversed,in
read_elf{32,64}_section_header_table'the order is correct, the issue isbetween those two functions.
I ran into some issues with
List.mapi: the standard OCaml version calls theiterator in the normal order meaning side effects (such as printing a debug
line) are correctly triggered. However the Lem version calls the iterator in the
reverse order, which is confusing. I'll definitely investigate this later.
The problem lies in
obtain_elf64_interpreted_sections: the section headerlist it eats is in the correct order, but the list of sections it returns is
reversed. After some more debugging I realized
Error.mapMreverses the listsit gets called with.
This patch fixes this issue and removes the previous workarounds.