The attribute r allows (or disallows for the negative case) read-only sections, i.e. ones without the SHF_WRITE flag, to be assigned to the memory region. Before the patch, lld could put a section in the wrong region or fail with "error: no memory region specified for section".
Details
Diff Detail
Event Timeline
Overall looks good to me. Some small suggestions for comments based on my thoughts when trying to reason about the change. These are only suggestions though, no strong opinions.
lld/ELF/LinkerScript.cpp | ||
---|---|---|
919 | Just a thought, could it be worth adding a member function to MemoryRegion, say compatibleWith(flags) which we could move this calculation into. That would put the calculation next to the comments that explain what the fields are. We'd then have if (m->compatibleWith(sec->flags)) here. | |
lld/ELF/LinkerScript.h | ||
142 | Could be worth saying ELF section flags instead of just flags to distinguish between Memory attibutes and Section flags. | |
146 | Could be worth an example. | |
152 | Suggest |
Thanks for the suggestions!
- Added method MemoryRegion::compatibleWith()
- Updated comments
Thanks for the update and sorry for the delay in responding. LGTM. Will be worth waiting a few days before committing to see if @MaskRay has any comments.
The attribute allows (or disallows for the negative case) read-only sections, i.e. ones without the SHF_WRITE flag, to be assigned to the memory region.
- i.e. ones without the SHF_WRITE flag + i.e. ones without the SHF_WRITE flag (`r`)
lld/test/ELF/linkerscript/memory-readonly.test | ||
---|---|---|
1 | Suggest renaming this to memory-neg-attr.test We can use this file to test all negative (!) attributes, not just readonly. | |
30 | Optional: can you figure out another memory region to test an attribute other than !r in the same test? |
Thanks for the suggestions!
- Updated comments
- memory-readonly.test -> memory-attr.test
- Added tests for all supported attributes
lld/test/ELF/linkerscript/memory-readonly.test | ||
---|---|---|
1 | The test checks both negative and positive cases, so I guess memory-attr.test will fit it better. | |
30 | I'll check all four supported attributes in the updated test. |
Could be worth saying ELF section flags instead of just flags to distinguish between Memory attibutes and Section flags.