Page MenuHomeFreeBSD

Put sections into expected offset in binary format.
ClosedPublic

Authored by ray on Sep 27 2019, 10:09 PM.
Tags
None
Referenced Files
F80105656: D21827.id.diff
Wed, Mar 27, 11:56 PM
Unknown Object (File)
Mon, Mar 25, 10:46 AM
Unknown Object (File)
Dec 21 2023, 11:18 PM
Unknown Object (File)
Dec 20 2023, 4:48 AM
Unknown Object (File)
Dec 11 2023, 2:01 AM
Unknown Object (File)
Sep 8 2023, 1:15 AM
Unknown Object (File)
Aug 14 2023, 9:53 PM
Unknown Object (File)
Aug 14 2023, 10:50 AM
Subscribers

Details

Summary

Calculate binary file offset using address field, bacause software know only offset to known data, not where to load segment.
With that patch, kernel .data section can have any alignment - kernel works.

PR: 235391

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

contrib/elftoolchain/elfcopy/binary.c
81 ↗(On Diff #62669)

Why keep "base"?

contrib/elftoolchain/elfcopy/binary.c
81 ↗(On Diff #62669)

As flags. Because sh_addr must not use special values.

contrib/elftoolchain/elfcopy/binary.c
81 ↗(On Diff #62669)

That claim should apply to sh_offset as well, shouldn't it? For position-independent objects we will have sh_offset == sh_addr.

contrib/elftoolchain/elfcopy/binary.c
81 ↗(On Diff #62669)

After objcopy -O binary done, nobody know it is PIC, loadable or anything else.

Can you show the readelf -S output for the input file where this change matters? The change looks ok to me, but I do not understand why it is useful.

Can you show the readelf -S output for the input file where this change matters? The change looks ok to me, but I do not understand why it is useful.

https://gist.github.com/rayddteam/270b5e564566c7a64841d58a9b34d7cd

markj added inline comments.
contrib/elftoolchain/elfcopy/binary.c
81 ↗(On Diff #62669)

Sure, but here we are talking about the input file, not the output file.

Anyway, if you insist on keeping both variables, I would rename base to baseoff.

116 ↗(On Diff #62669)

Should be baseaddr now.

This revision is now accepted and ready to land.Sep 28 2019, 5:09 PM

Rename base to baseoff. Fix comment.

This revision now requires review to proceed.Sep 29 2019, 9:17 PM
ray marked 2 inline comments as done.Sep 29 2019, 9:17 PM
contrib/elftoolchain/elfcopy/binary.c
81 ↗(On Diff #62669)

About claim: not exact same. baseoff(base before) is off_t, which is big enough to never reach '-1' and in that case used on value, that can't be negative. So, not clearly, but can be used with special value. About Elf64_Addr, we can't be sure what address will be selected to start kernel on platform. We can use special value 0xff..f, but it will looks more magic than just -1 :)

This revision is now accepted and ready to land.Sep 29 2019, 10:19 PM
This revision was automatically updated to reflect the committed changes.