-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
llvm-objcopy: Emit warnings when handling sparse ELF files #88878
Comments
cc @MaskRay |
@llvm/issue-subscribers-tools-llvm-objcopy-strip Author: Djordje Todorovic (djtodoro)
The `objcopy` from GNU binutils (`bfd` actually [0]) when dealing with sparse ELF input file reports warning like:
Can we implement something like this in [0] https://github.com/bminor/binutils-gdb/blob/master/bfd/binary.c#L277 |
Could you clarify what you mean by "sparse" ELF files? I'm not aware of a feature like that in the regular ELF standard (that's not to say we don't care about it, I'm just not familiar with the concept). Also, could you outline your use-case, please? In other words, why would a warning be helpful?
Not directly. Rather than explain the full thing, I refer you to my lightning talk on error handling in libraries: https://www.youtube.com/watch?v=YSEY4pg1YB0. Whilst this specifically talks about the DWARF debug code, the principles are generic. You'll want a way of bubbling up a warning to the tool layer, so that the llvm-objcopy tool itself can properly handle the warning. That being said, I suspect a warning won't be what we actually want. Either the tool should support a kind of file, in which case it should be able to handle it properly without warnings, or it shouldn't, in which case it should generate an error when it encounters such a file. I'm not convinced without more information that a warning like this would make sense. |
Hi @jh7370 for your answer. I am really sorry for putting this on the side. In general, "sparse" ELF is not a standardized term, but it refers to instances where there is unused content between sections in the binary. objcopy from binutils is capable of recognizing such examples. For instance, here is a very simple YAML/ELF that illustrates this concept (representing a MIPS 32-bit target, as LLVM will report an out-of-memory error for a similar scenario with a 64-bit target):
The
It would be useful to prevent llvm-objcopy from creating files like this. The warning I mentioned can be implemented as an |
Thank you for the explanation. Just to make sure expectations are clear: I don't routinely make code changes to LLVM, but I do try to review some areas of code (llvm-objcopy being one such area). As such, for this issue to be fixed, somebody else will need to do the actual coding. I don't think we can generate an |
Sure. Thanks a lot. I will do the codding.
Hmm, it makes sense. Let me double check what is the best way to achieve that, and I will be back. |
Copying my comment at #97036 Frankly, I hope that we leave llvm-objcopy unchanged. Users can request object files with sections exceeding 0x80000000, and llvm-objcopy should handle those requests as intended. Note: we did introduce a default size limit for yaml2obj (10MiB) reviews.llvm.org/D81258 . |
Hi @MaskRay, thanks a lot for your comment! The problem itself is not in the |
Hi @MaskRay, The idea is to assume that everything is placed at a certain address (let's say I've managed to (somewhat) reproduce the problem with a simple case for the MIPS architecture:
By default, we won't see the file truncated error report, since the section at a negative offset (".pdr") won't be loaded, so it is being ignored by objcopy.
(even though the file position/offset is negative for the section: -1073741824). But, if I add a load flag for the section it will be reported:
This issue isn't just theoretical; it reflects a real use-case with one of our embedded targets. The Given these practical implications, having an optional flag in In embedded systems, size really matters, and the file truncated error from BFD ( Thanks again for your insights. |
@MaskRay any comment on this? |
cc @jh7370 :) |
OK. I wanted to double check if you may have some additional inputs after those additional comments I have made. Sorry about that. I will wait for @MaskRay. |
Do you know why the error message I don't see the error with i386.
The binutils condition is |
@MaskRay Thanks for the comment! I would say that the C code I shared isn't the most effective reproducer, and it requires more intricate adjustments in the linker script to achieve the desired behavior.
When we are using the latest So, in [2], since [0] https://github.com/bminor/binutils-gdb/blob/master/bfd/binary.c#L258 |
Thanks for the explanation. So this condition is enabled when binutils is built for 32-bit targets. llvm-project generally tries to avoid 32-bit/64-bit differences and I'd certainly avoid such checks. Since we prefer generality and want to avoid magic values, If you want to limit output file sizes, use |
In this particular case, yes, but I think we can create a scenario where the offset becomes negative even in BFD 64-bit configuration.
Eh, I see your point. I would like to see the error/warning triggered in any case where we have "Sparse ELF" generated - so the gap without useful data after using the
Thanks for the recommendation, but I think I see two problems with this:
|
There is no such concept called "Sparse ELF". It is probably mentioned in one binutils comment, but is never accepted widely. For example, we could argue that output files > 4GiB are weird, but it could be very valid to generate such files (it's also correct even if we use regular .rodata,.data,.text - valid in x86-64 large code model and other architectures' large code model).
rlimit is per-process. You can do this:
|
Sure, we are on the same page about that - that is why I use quotation marks when mentioning Sparse ELF. Just to clarify, I do not want to say that the ELF produced is wrong, but it would be very beneficial for some teams to have an option to prevent this type of ELF. The option we are proposing is off by default, and I guess easy to be maintained.
Yeah, I agree. However, the problem we are trying to solve isn't the size of the file itself, but rather the large gap between sections in the ELF file (which is connected to/mentioned in the item 2).
|
The
objcopy
from GNU binutils (bfd
actually [0]) when dealing with sparse ELF input file reports warning like:Can we implement something like this in
llvm-objcopy
? Since the logic for copying is implemented within theELFObjcopy
which is being used in modules other thanllvm-objcopy
, is it OK to emit warning in the library it self?[0] https://github.com/bminor/binutils-gdb/blob/master/bfd/binary.c#L277
The text was updated successfully, but these errors were encountered: