This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [Patch] ld: check for address space overflow
On Tue, Mar 14, 2017 at 1:15 AM, Tristan Gingold <gingold@adacore.com> wrote:
> [...]
>
>> This works:
>>
>> diff --git a/ld/ldlang.c b/ld/ldlang.c
>> index a0638ea..8c1d829 100644
>> --- a/ld/ldlang.c
>> +++ b/ld/ldlang.c
>> @@ -4783,13 +4783,13 @@ lang_check_section_addresses (void)
>> for (s = link_info.output_bfd->sections; s != NULL; s = s->next)
>> {
>> s_end = (s->vma + s->size) & addr_mask;
>> - if (s_end != 0 && s_end < s->vma)
>> + if (s_end != 0 && s_end < (s->vma & addr_mask))
>> einfo (_("%X%P: section %s VMA wraps around address space\n"),
>> s->name);
>> else
>> {
>> s_end = (s->lma + s->size) & addr_mask;
>> - if (s_end != 0 && s_end < s->lma)
>> + if (s_end != 0 && s_end < (s->lma & addr_mask))
>> einfo (_("%X%P: section %s LMA wraps around address space\n"),
>> s->name);
>> }
>
> Yes, that makes sense.
> Do you plan to commit it ?
>
This is what I checked in.
--
H.J.
---
>From 9216a6f33592c350ad50696d5571c82e47b71a5e Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 14 Mar 2017 09:09:54 -0700
Subject: [PATCH] Use addr_mask to check VMA and LMA
Since BFD64 may be used on 32-bit address, we need to apply addr_mask
to check VMA and LMA.
* ldlang.c (lang_check_section_addresses): Use addr_mask to
check VMA and LMA.
---
ld/ChangeLog | 5 +++++
ld/ldlang.c | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/ld/ChangeLog b/ld/ChangeLog
index eb0c309..df8bb32 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,8 @@
+2017-03-14 H.J. Lu <hongjiu.lu@intel.com>
+
+ * ldlang.c (lang_check_section_addresses): Use addr_mask to
+ check VMA and LMA.
+
2017-03-13 Nick Clifton <nickc@redhat.com>
PR binutils/21202
diff --git a/ld/ldlang.c b/ld/ldlang.c
index a0638ea..8c1d829 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -4783,13 +4783,13 @@ lang_check_section_addresses (void)
for (s = link_info.output_bfd->sections; s != NULL; s = s->next)
{
s_end = (s->vma + s->size) & addr_mask;
- if (s_end != 0 && s_end < s->vma)
+ if (s_end != 0 && s_end < (s->vma & addr_mask))
einfo (_("%X%P: section %s VMA wraps around address space\n"),
s->name);
else
{
s_end = (s->lma + s->size) & addr_mask;
- if (s_end != 0 && s_end < s->lma)
+ if (s_end != 0 && s_end < (s->lma & addr_mask))
einfo (_("%X%P: section %s LMA wraps around address space\n"),
s->name);
}
--
2.9.3