[memory-region] Error when section VMA does not fit in region#1102
[memory-region] Error when section VMA does not fit in region#1102deepakshirkem wants to merge 1 commit intoqualcomm:mainfrom
Conversation
| #START_TEST | ||
| RUN: %clang %clangg0opts -o %t1.1.o %p/Inputs/1.c -c -ffunction-sections | ||
| RUN: %not %link %linkopts -o %t1.1.out %t1.1.o -T %p/Inputs/script.t 2>&1 | %filecheck %s | ||
| #CHECK: section '.foo' will not fit in region 'RAM' |
There was a problem hiding this comment.
There is no error with bfd linker.
| << sec->name() << region.getName() << (secEnd - regionEnd); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
With bfd, any explicit address specified, is not assigned to the memory region.
Probably the user needs to be notified, that this output section is not part of the memory region as a note, and also a linker script warning using -Wlinker-script that this section is outside the memory region bounds.
In any case these might be needed to be moved to ScriptMemoryRegion to flag.
There was a problem hiding this comment.
Hi @quic-seaswara, My initial thought was also to add this check in ScriptMemoryRegion or verifyMemoryRegions(), but during debugging I found that final section addresses are not yet assigned at that point (they are still 0x0).That's why I moved the check to postLayout() where addresses are fully assigned. That's why I moved the check to postLayout() where addresses are fully assigned.
I will address suggested comments those are making more sense.
Thank You ::((
c171680 to
87bc13a
Compare
|
Hi @quic-seaswara, Thank you ::(( |
|
Hi @quic-seaswara / @quic-areg, Please take another look at these changes when you get a chance? |
| uint64_t vma = out->prolog().vma().result(); | ||
| if (!containsVMA(vma)) | ||
| Config.raise(Diag::warn_section_not_in_region) | ||
| << out->name() << getName() << utility::toHex(vma); |
There was a problem hiding this comment.
Need the linker script file also in the warning message.
| if (&out->epilog().region() != this) | ||
| continue; | ||
| if (!out->prolog().hasVMA()) | ||
| continue; |
There was a problem hiding this comment.
You might want to move this condition to line 51 ?
| for (auto *out : SectMap) { | ||
| if (!out->epilog().hasRegion()) | ||
| continue; | ||
| if (&out->epilog().region() != this) |
There was a problem hiding this comment.
Instead of passing the sectionMap can verifyMemoryRegions run on all output sections that have memory region and call verifyMemoryUsage ? The code can be greatly simplified I think.
Note : the original loop will not change,
| #START_TEST | ||
| RUN: %clang %clangg0opts -o %t1.1.o %p/Inputs/1.c -c -ffunction-sections | ||
| RUN: %link %linkopts -o %t1.1.out %t1.1.o -T %p/Inputs/script.t -Wlinker-script 2>&1 | %filecheck %s | ||
| RUN: %link %linkopts -o %t1.2.out %t1.1.o -T %p/Inputs/script.t 2>&1 | %filecheck %s --check-prefix=NOWARN --allow-empty |
| #---MemoryRegionVMACheck.test----------------------- Executable -----------------# | ||
| #BEGIN_COMMENT | ||
| # Test that ELD emits a warning when a section VMA does not fit | ||
| # in its assigned memory region, matching BFD behavior. |
There was a problem hiding this comment.
Does bfd emit a warning by default ?
|
Hi @quic-seaswara, I apologize for the misunderstanding. I have not addressed these comments carefully enough.
I have re-verified the behavior both BFD and LLD error out for this test case. If you give me the go-ahead, I will implement this as an error to match BFD and LLD behavior. |
ELD did not report any error when a section's explicit VMA does not fit within its assigned memory region. Both BFD and LLD error out in this case. Fix by: - Changing warn_section_not_in_region to error_section_not_in_region - Adding linker script file context to the error message - Simplifying verifyMemoryUsage to take a single OutputSectionEntry instead of SectionMap, matching LLD's checkMemoryRegion pattern - Moving the section loop to verifyMemoryRegions in GNULDBackend Fixes qualcomm#327. Signed-off-by: deepakshirkem <deepakshirke509@gmail.com>
87bc13a to
4ece383
Compare
|
Hi @quic-seaswara, please review the latest changes. I have matched the BFD behavior: ELD:
Thank You ::)) |


Problem
Fixes #327
ELD was silently linking when a section's VMA was placedoutside its assigned memory region bounds:
Fix
Added check in
postLayout()to verify each section's VMA fits within its assigned memory region bounds, matching LLDbehavior exactly:
Error: section '.foo' will not fit in region 'RAM':overflowed by 1288 bytesTesting
Added test
MemoryRegionVMACheckthat verifies ELD emits a clear error when a section VMA does not fit in itsassigned memory region.
cc @parth-07 @quic-seaswara