debug/elf: (*Section).Data() returns non-zero data for SHT_NOBITS section #18667
Comments
I would be inclined to return an error of the That said, I would reconsider if that choice breaks real programs that seem otherwise correct. |
Return an error from both (*Section).Open and (*Section).Data is also fine
with me.
The current behavior of silently returning wrong data (and nil error)
should be fixed.
|
Bumping to Go 1.10 for lack of activity. |
If we don't return an error we have to decide between returning []byte{} and make([]byte, Size). Better to return an error and make the user understand what's going on. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(*Section).Data fails to take section.Type == Type:elf.SHT_NOBITS into account, and will happily return anything in the file at the section file offset.
On certain ELF files, debug/elf will output non-zero data for .bss section.
For example, compile the following assembly file as a shared library:
This is because the .comment section happens to be after the .bss section.
Perhaps this is a user error, but I'm not entirely sure. And if it is indeed a bug of debug/elf, I'm not sure whether we should make it return
make([]byte, section.Size)
or just an error indicating that the section doesn't have file data. I'm leaning towards returning a zero byte slice./cc @ianlancetaylor
The text was updated successfully, but these errors were encountered: