This is an archive of the discontinued LLVM Phabricator instance.

[LLD][COFF] Implement /filealign parameter
ClosedPublic

Authored by thrimbor on May 20 2019, 1:11 AM.

Details

Reviewers
ruiu
Summary

This adds the /filealign parameter to lld, which allows to specify the section alignment in the output file (as it does on Microsoft's link.exe).
This is required to be able to load dynamically linked libraries on the original Xbox, where the debugger monitor expects the section alignment in the file to be the same as in memory.

Diff Detail

Event Timeline

thrimbor created this revision.May 20 2019, 1:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 20 2019, 1:11 AM
ruiu added a comment.May 20 2019, 1:18 AM

Can you write a patch description? Please mention that Microsoft link.exe has this option.

Could you tell me a little bit about why you wanted this option?

It needs a testcase.

lld/COFF/Config.h
183

We use the same name for a command line option and a Config member name, so FileAlign.

thrimbor updated this revision to Diff 200382.EditedMay 20 2019, 6:28 PM

Changed Config member name, added a test.

The test currently only checks the FileAlignment header field - I wanted to check the individual section offsets, too, but llvm-objdump doesn't expose this information.

thrimbor edited the summary of this revision. (Show Details)May 20 2019, 6:35 PM
ruiu added a comment.May 20 2019, 7:30 PM

Did you personally need this? Or are you adding this just for completeness?

Either case is fine, but I'd like to know what is a use case of this feature.

Did you personally need this? Or are you adding this just for completeness?

Either case is fine, but I'd like to know what is a use case of this feature.

I didn't need this myself, but the need for it came up during the work of another XboxDev member who worked on adding support for debug extensions to our toolchain targeting the original Xbox (called nxdk), and I decided to try and add this feature. Due to the lack of /filealign-support we currently have a workaround in place: https://github.com/JayFoxRox/nxdk/pull/10/commits/1822465478b04ca18d5544c103bfe743ad47876c#diff-6ffdcfc2a5d215955b49510d4547fc8cR19

Ideally we would be able to have filealign==align (which this patch makes possible, removing the need for the workaround) and be able to choose a small value for this (which would require hooking up /align, which I do plan to do, too) to minimize memory usage (the Xbox only has 64MiB of RAM and there has to be enough left for the application, so our debug extensions aren't allowed to consume much space).

ruiu added a comment.May 20 2019, 10:03 PM

Th

lld/COFF/Driver.cpp
1190

Thank you for your explanation. One last thing -- can you add a check to make sure that a parsed value is a power of two?

thrimbor updated this revision to Diff 200416.May 21 2019, 12:33 AM

I updated the patch to include a power-of-two check.

ruiu accepted this revision.May 21 2019, 12:53 AM

LGTM

This revision is now accepted and ready to land.May 21 2019, 12:53 AM