This is an archive of the discontinued LLVM Phabricator instance.

[LLD] Extend /section to be compatible to MSVC link.exe
Needs ReviewPublic

Authored by ydinkin on Nov 4 2019, 3:24 PM.

Details

Reviewers
ruiu
Summary

MSVC link.exe implements the /section flag for modification of section attributes.
Before, lld-link only supported rudimentary usage of said flag, which prevented
fine-grained control such as disabling attributes and overriding access.
Now, it is compatible with MSVC link.exe, including undocumented but relied upon behaviors.

Diff Detail

Event Timeline

ydinkin created this revision.Nov 4 2019, 3:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2019, 3:24 PM
ruiu added inline comments.Nov 5 2019, 5:35 AM
lld/COFF/Config.h
88

I feel enabled/disabled are better names than enable/disable.

access is not actually a mask but a value itself, so AttributeMask might be little bit confusing.

How about this? Rename this struct SectionAttributes, and rename members enabledFlags, disabledFlags and accessBits.

nit: separate members by ; instead of ,.

lld/COFF/DriverUtils.cpp
172

I'd copy values instead of taking pointers, and assign back to mask.enable and mask.disable at the end of this function, so that we can eliminate *s.

ydinkin added inline comments.Nov 5 2019, 7:22 AM
lld/COFF/Config.h
88

You're right, I'll rename the struct.
However, I'd like to preserve the distinction between set values and bitmasks,
how about enableMask, disableMask & accessBits? If you prefer, we can go for enabledMask/disabledMask - but the infinitive seems better, personally.

lld/COFF/DriverUtils.cpp
172

The pointers are the most elegant I could find since they allow to both set the correct field & preserve the information of whether we're currently enabling or disabling flags.
In order to avoid using pointers, we'd have to not only keep uint32_t for the later assign (as you suggested), but also a bool so we can track how they should be assigned.

ydinkin marked 2 inline comments as done.Nov 6 2019, 11:14 PM
ruiu added inline comments.Nov 6 2019, 11:24 PM
lld/COFF/Config.h
88

enableMask/disableMask/accessBits sounds good to me.

lld/COFF/DriverUtils.cpp
172

OK, if you prefer pointers I'm fine with that.

ydinkin updated this revision to Diff 228408.Nov 8 2019, 3:47 AM

Fixed review comments, mainly renames,
Also, fixed parseSectionAttributes (previously parseSectionAttributeMask) returning an unused value.
After second thought, also decided to change said function to avoid using pointers.

ydinkin marked 4 inline comments as done.Nov 8 2019, 3:48 AM