* [Patch] ld: check for address space overflow
@ 2017-03-10 14:29 Tristan Gingold
2017-03-11 1:14 ` Alan Modra
2017-03-13 19:06 ` H.J. Lu
0 siblings, 2 replies; 14+ messages in thread
From: Tristan Gingold @ 2017-03-10 14:29 UTC (permalink / raw)
To: binutils
Hello,
currently the linker allows to put a section which starts near the end of the address space and which ends past the end (so wrap around). I think this should be flagged as an error.
No regression on powerpc-elf
Ok for master ?
Tristan.
commit 09718888d36a07cc9c71aa301a39a4299dbf8c34
Author: Tristan Gingold <gingold@adacore.com>
Date: Fri Mar 10 15:16:19 2017 +0100
ld: add an error in case of address space overflow.
ld/
* ldlang.c (lang_check_section_addresses): Check for address space
overflow.
* testsuite/ld-checks/checks.exp (overflow_check): New procedure
* testsuite/ld-checks/over.s: New test source.
* testsuite/ld-checks/over.d: New test.
* testsuite/ld-checks/over2.s: New test source.
* testsuite/ld-checks/over2.d: New test.
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 3883bcb..5387210 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,13 @@
+2017-03-10 Tristan Gingold <gingold@adacore.com>
+
+ * ldlang.c (lang_check_section_addresses): Check for address space
+ overflow.
+ * testsuite/ld-checks/checks.exp (overflow_check): New procedure
+ * testsuite/ld-checks/over.s: New test source.
+ * testsuite/ld-checks/over.d: New test.
+ * testsuite/ld-checks/over2.s: New test source.
+ * testsuite/ld-checks/over2.d: New test.
+
2017-03-07 Alan Modra <amodra@gmail.com>
* ldlang.c (open_input_bfds): Check that lang_assignment_statement
diff --git a/ld/ldlang.c b/ld/ldlang.c
index ff6ef39..36b6884 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -4768,6 +4768,7 @@ lang_check_section_addresses (void)
asection *s, *p;
struct check_sec *sections;
size_t i, count;
+ bfd_vma addr_mask;
bfd_vma s_start;
bfd_vma s_end;
bfd_vma p_start = 0;
@@ -4775,6 +4776,25 @@ lang_check_section_addresses (void)
lang_memory_region_type *m;
bfd_boolean overlays;
+ /* Detect address space overflow. */
+ addr_mask = ((bfd_vma) 1 <<
+ (bfd_arch_bits_per_address (link_info.output_bfd) - 1)) - 1;
+ addr_mask = (addr_mask << 1) + 1;
+ 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)
+ 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)
+ einfo (_("%X%P: section %s LMA wraps around address space\n"),
+ s->name);
+ }
+ }
+
if (bfd_count_sections (link_info.output_bfd) <= 1)
return;
diff --git a/ld/testsuite/ld-checks/checks.exp b/ld/testsuite/ld-checks/checks.exp
index b1c8454..782f50a 100644
--- a/ld/testsuite/ld-checks/checks.exp
+++ b/ld/testsuite/ld-checks/checks.exp
@@ -78,4 +78,17 @@ proc section_check {} {
}
}
+proc overflow_check {} {
+ # Test only on some 32-bit targets that are often tested
+ if { ![istarget i?86-*-*]
+ && ![istarget powerpc-*-*]
+ && ![istarget arm*-*-*] } {
+ return
+ }
+
+ run_dump_test "over"
+ run_dump_test "over2"
+}
+
section_check
+overflow_check
diff --git a/ld/testsuite/ld-checks/over.d b/ld/testsuite/ld-checks/over.d
new file mode 100644
index 0000000..e34bea9
--- /dev/null
+++ b/ld/testsuite/ld-checks/over.d
@@ -0,0 +1,4 @@
+#name: section size overflow
+#source: over.s
+#ld: -Ttext=0xfffffffc
+#error: .* section .text VMA wraps around address space
diff --git a/ld/testsuite/ld-checks/over.s b/ld/testsuite/ld-checks/over.s
new file mode 100644
index 0000000..7f8d4b5
--- /dev/null
+++ b/ld/testsuite/ld-checks/over.s
@@ -0,0 +1,7 @@
+ .text
+ .globl _start
+_start:
+ .long 0
+ .long 0
+ .long 0
+ .long 0
diff --git a/ld/testsuite/ld-checks/over2.d b/ld/testsuite/ld-checks/over2.d
new file mode 100644
index 0000000..511b917
--- /dev/null
+++ b/ld/testsuite/ld-checks/over2.d
@@ -0,0 +1,8 @@
+#name: section size overflow
+#source: over2.s
+#ld: -Ttext=0xfffffffc
+#nm: -n
+
+#...
+fffffffc T _start
+#pass
diff --git a/ld/testsuite/ld-checks/over2.s b/ld/testsuite/ld-checks/over2.s
new file mode 100644
index 0000000..dc6de0e
--- /dev/null
+++ b/ld/testsuite/ld-checks/over2.s
@@ -0,0 +1,4 @@
+ .text
+ .globl _start
+_start:
+ .long 0
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Patch] ld: check for address space overflow
2017-03-10 14:29 [Patch] ld: check for address space overflow Tristan Gingold
@ 2017-03-11 1:14 ` Alan Modra
2017-03-13 9:47 ` Tristan Gingold
2017-03-13 19:06 ` H.J. Lu
1 sibling, 1 reply; 14+ messages in thread
From: Alan Modra @ 2017-03-11 1:14 UTC (permalink / raw)
To: Tristan Gingold; +Cc: binutils
On Fri, Mar 10, 2017 at 03:29:24PM +0100, Tristan Gingold wrote:
> ld: add an error in case of address space overflow.
>
> ld/
> * ldlang.c (lang_check_section_addresses): Check for address space
> overflow.
> * testsuite/ld-checks/checks.exp (overflow_check): New procedure
> * testsuite/ld-checks/over.s: New test source.
> * testsuite/ld-checks/over.d: New test.
> * testsuite/ld-checks/over2.s: New test source.
> * testsuite/ld-checks/over2.d: New test.
OK.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Patch] ld: check for address space overflow
2017-03-11 1:14 ` Alan Modra
@ 2017-03-13 9:47 ` Tristan Gingold
2017-03-13 17:52 ` H.J. Lu
0 siblings, 1 reply; 14+ messages in thread
From: Tristan Gingold @ 2017-03-13 9:47 UTC (permalink / raw)
To: Alan Modra; +Cc: binutils
> On 11 Mar 2017, at 02:14, Alan Modra <amodra@gmail.com> wrote:
>
> On Fri, Mar 10, 2017 at 03:29:24PM +0100, Tristan Gingold wrote:
>> ld: add an error in case of address space overflow.
>>
>> ld/
>> * ldlang.c (lang_check_section_addresses): Check for address space
>> overflow.
>> * testsuite/ld-checks/checks.exp (overflow_check): New procedure
>> * testsuite/ld-checks/over.s: New test source.
>> * testsuite/ld-checks/over.d: New test.
>> * testsuite/ld-checks/over2.s: New test source.
>> * testsuite/ld-checks/over2.d: New test.
>
> OK.
Thanks, just committed.
Tristan.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Patch] ld: check for address space overflow
2017-03-13 9:47 ` Tristan Gingold
@ 2017-03-13 17:52 ` H.J. Lu
0 siblings, 0 replies; 14+ messages in thread
From: H.J. Lu @ 2017-03-13 17:52 UTC (permalink / raw)
To: Tristan Gingold; +Cc: Alan Modra, binutils
On Mon, Mar 13, 2017 at 2:46 AM, Tristan Gingold <gingold@adacore.com> wrote:
>
>> On 11 Mar 2017, at 02:14, Alan Modra <amodra@gmail.com> wrote:
>>
>> On Fri, Mar 10, 2017 at 03:29:24PM +0100, Tristan Gingold wrote:
>>> ld: add an error in case of address space overflow.
>>>
>>> ld/
>>> * ldlang.c (lang_check_section_addresses): Check for address space
>>> overflow.
>>> * testsuite/ld-checks/checks.exp (overflow_check): New procedure
>>> * testsuite/ld-checks/over.s: New test source.
>>> * testsuite/ld-checks/over.d: New test.
>>> * testsuite/ld-checks/over2.s: New test source.
>>> * testsuite/ld-checks/over2.d: New test.
>>
>> OK.
>
> Thanks, just committed.
>
> Tristan.
>
This caused
FAIL: ld-elf/loadaddr1
FAIL: ld-elf/loadaddr2
FAIL: ld-elf/seg
on Linux/i386 with 64-bit VMA.
--
H.J.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Patch] ld: check for address space overflow
2017-03-10 14:29 [Patch] ld: check for address space overflow Tristan Gingold
2017-03-11 1:14 ` Alan Modra
@ 2017-03-13 19:06 ` H.J. Lu
2017-03-13 19:27 ` H.J. Lu
1 sibling, 1 reply; 14+ messages in thread
From: H.J. Lu @ 2017-03-13 19:06 UTC (permalink / raw)
To: Tristan Gingold; +Cc: binutils
On Fri, Mar 10, 2017 at 6:29 AM, Tristan Gingold <gingold@adacore.com> wrote:
> Hello,
>
> currently the linker allows to put a section which starts near the end of the address space and which ends past the end (so wrap around). I think this should be flagged as an error.
>
> No regression on powerpc-elf
>
> Ok for master ?
>
> Tristan.
>
> commit 09718888d36a07cc9c71aa301a39a4299dbf8c34
> Author: Tristan Gingold <gingold@adacore.com>
> Date: Fri Mar 10 15:16:19 2017 +0100
>
> ld: add an error in case of address space overflow.
>
> ld/
> * ldlang.c (lang_check_section_addresses): Check for address space
> overflow.
> * testsuite/ld-checks/checks.exp (overflow_check): New procedure
> * testsuite/ld-checks/over.s: New test source.
> * testsuite/ld-checks/over.d: New test.
> * testsuite/ld-checks/over2.s: New test source.
> * testsuite/ld-checks/over2.d: New test.
>
> diff --git a/ld/ChangeLog b/ld/ChangeLog
> index 3883bcb..5387210 100644
> --- a/ld/ChangeLog
> +++ b/ld/ChangeLog
> @@ -1,3 +1,13 @@
> +2017-03-10 Tristan Gingold <gingold@adacore.com>
> +
> + * ldlang.c (lang_check_section_addresses): Check for address space
> + overflow.
> + * testsuite/ld-checks/checks.exp (overflow_check): New procedure
> + * testsuite/ld-checks/over.s: New test source.
> + * testsuite/ld-checks/over.d: New test.
> + * testsuite/ld-checks/over2.s: New test source.
> + * testsuite/ld-checks/over2.d: New test.
> +
> 2017-03-07 Alan Modra <amodra@gmail.com>
>
> * ldlang.c (open_input_bfds): Check that lang_assignment_statement
> diff --git a/ld/ldlang.c b/ld/ldlang.c
> index ff6ef39..36b6884 100644
> --- a/ld/ldlang.c
> +++ b/ld/ldlang.c
> @@ -4768,6 +4768,7 @@ lang_check_section_addresses (void)
> asection *s, *p;
> struct check_sec *sections;
> size_t i, count;
> + bfd_vma addr_mask;
> bfd_vma s_start;
> bfd_vma s_end;
> bfd_vma p_start = 0;
> @@ -4775,6 +4776,25 @@ lang_check_section_addresses (void)
> lang_memory_region_type *m;
> bfd_boolean overlays;
>
> + /* Detect address space overflow. */
> + addr_mask = ((bfd_vma) 1 <<
> + (bfd_arch_bits_per_address (link_info.output_bfd) - 1)) - 1;
This isn't correct. See is32bit () in bfd.c. And it doesn't work
for -0x80000000 with 64-bit VMA for 32-bit targets.
> + addr_mask = (addr_mask << 1) + 1;
> + 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)
> + 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)
> + einfo (_("%X%P: section %s LMA wraps around address space\n"),
> + s->name);
> + }
> + }
> +
> if (bfd_count_sections (link_info.output_bfd) <= 1)
> return;
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Patch] ld: check for address space overflow
2017-03-13 19:06 ` H.J. Lu
@ 2017-03-13 19:27 ` H.J. Lu
2017-03-14 8:15 ` Tristan Gingold
0 siblings, 1 reply; 14+ messages in thread
From: H.J. Lu @ 2017-03-13 19:27 UTC (permalink / raw)
To: Tristan Gingold; +Cc: binutils
On Mon, Mar 13, 2017 at 12:06 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, Mar 10, 2017 at 6:29 AM, Tristan Gingold <gingold@adacore.com> wrote:
>> Hello,
>>
>> currently the linker allows to put a section which starts near the end of the address space and which ends past the end (so wrap around). I think this should be flagged as an error.
>>
>> No regression on powerpc-elf
>>
>> Ok for master ?
>>
>> Tristan.
>>
>> commit 09718888d36a07cc9c71aa301a39a4299dbf8c34
>> Author: Tristan Gingold <gingold@adacore.com>
>> Date: Fri Mar 10 15:16:19 2017 +0100
>>
>> ld: add an error in case of address space overflow.
>>
>> ld/
>> * ldlang.c (lang_check_section_addresses): Check for address space
>> overflow.
>> * testsuite/ld-checks/checks.exp (overflow_check): New procedure
>> * testsuite/ld-checks/over.s: New test source.
>> * testsuite/ld-checks/over.d: New test.
>> * testsuite/ld-checks/over2.s: New test source.
>> * testsuite/ld-checks/over2.d: New test.
>>
>> diff --git a/ld/ChangeLog b/ld/ChangeLog
>> index 3883bcb..5387210 100644
>> --- a/ld/ChangeLog
>> +++ b/ld/ChangeLog
>> @@ -1,3 +1,13 @@
>> +2017-03-10 Tristan Gingold <gingold@adacore.com>
>> +
>> + * ldlang.c (lang_check_section_addresses): Check for address space
>> + overflow.
>> + * testsuite/ld-checks/checks.exp (overflow_check): New procedure
>> + * testsuite/ld-checks/over.s: New test source.
>> + * testsuite/ld-checks/over.d: New test.
>> + * testsuite/ld-checks/over2.s: New test source.
>> + * testsuite/ld-checks/over2.d: New test.
>> +
>> 2017-03-07 Alan Modra <amodra@gmail.com>
>>
>> * ldlang.c (open_input_bfds): Check that lang_assignment_statement
>> diff --git a/ld/ldlang.c b/ld/ldlang.c
>> index ff6ef39..36b6884 100644
>> --- a/ld/ldlang.c
>> +++ b/ld/ldlang.c
>> @@ -4768,6 +4768,7 @@ lang_check_section_addresses (void)
>> asection *s, *p;
>> struct check_sec *sections;
>> size_t i, count;
>> + bfd_vma addr_mask;
>> bfd_vma s_start;
>> bfd_vma s_end;
>> bfd_vma p_start = 0;
>> @@ -4775,6 +4776,25 @@ lang_check_section_addresses (void)
>> lang_memory_region_type *m;
>> bfd_boolean overlays;
>>
>> + /* Detect address space overflow. */
>> + addr_mask = ((bfd_vma) 1 <<
>> + (bfd_arch_bits_per_address (link_info.output_bfd) - 1)) - 1;
>
> This isn't correct. See is32bit () in bfd.c. And it doesn't work
> for -0x80000000 with 64-bit VMA for 32-bit targets.
>
>> + addr_mask = (addr_mask << 1) + 1;
>> + 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)
>> + 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)
>> + einfo (_("%X%P: section %s LMA wraps around address space\n"),
>> + s->name);
>> + }
>> + }
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);
}
>> +
>> if (bfd_count_sections (link_info.output_bfd) <= 1)
>> return;
--
H.J.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Patch] ld: check for address space overflow
2017-03-13 19:27 ` H.J. Lu
@ 2017-03-14 8:15 ` Tristan Gingold
2017-03-14 10:20 ` Alan Modra
2017-03-14 16:13 ` H.J. Lu
0 siblings, 2 replies; 14+ messages in thread
From: Tristan Gingold @ 2017-03-14 8:15 UTC (permalink / raw)
To: H.J. Lu; +Cc: binutils
[...]
> 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 ?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Patch] ld: check for address space overflow
2017-03-14 8:15 ` Tristan Gingold
@ 2017-03-14 10:20 ` Alan Modra
2017-03-14 10:50 ` Tristan Gingold
2017-03-14 16:13 ` H.J. Lu
1 sibling, 1 reply; 14+ messages in thread
From: Alan Modra @ 2017-03-14 10:20 UTC (permalink / raw)
To: Tristan Gingold; +Cc: H.J. Lu, binutils
On Tue, Mar 14, 2017 at 09:15:30AM +0100, Tristan Gingold 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 ?
The new testcases need some tweaking too. Even after applying the
above I'm left with:
arm-aout +FAIL: section size overflow
arm-coff +FAIL: section size overflow
arm-epoc-pe +FAIL: section size overflow
arm-pe +FAIL: section size overflow
arm-symbianelf +FAIL: section size overflow
arm-wince-pe +FAIL: section size overflow
i386-linuxaout +FAIL: section size overflow
i386-linuxaout +FAIL: section size overflow
i386-lynxos +FAIL: section size overflow
i386-netware +FAIL: section size overflow
i586-aout +FAIL: section size overflow
i686-pe +FAIL: section size overflow
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Patch] ld: check for address space overflow
2017-03-14 10:20 ` Alan Modra
@ 2017-03-14 10:50 ` Tristan Gingold
2017-03-14 12:17 ` Alan Modra
0 siblings, 1 reply; 14+ messages in thread
From: Tristan Gingold @ 2017-03-14 10:50 UTC (permalink / raw)
To: Alan Modra; +Cc: H.J. Lu, binutils
> On 14 Mar 2017, at 11:19, Alan Modra <amodra@gmail.com> wrote:
>
> On Tue, Mar 14, 2017 at 09:15:30AM +0100, Tristan Gingold 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 ?
>
> The new testcases need some tweaking too. Even after applying the
> above I'm left with:
>
> arm-aout +FAIL: section size overflow
> arm-coff +FAIL: section size overflow
> arm-epoc-pe +FAIL: section size overflow
> arm-pe +FAIL: section size overflow
> arm-symbianelf +FAIL: section size overflow
> arm-wince-pe +FAIL: section size overflow
> i386-linuxaout +FAIL: section size overflow
> i386-linuxaout +FAIL: section size overflow
> i386-lynxos +FAIL: section size overflow
> i386-netware +FAIL: section size overflow
> i586-aout +FAIL: section size overflow
> i686-pe +FAIL: section size overflow
What is the host ? 32 bit or 64 bit ?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Patch] ld: check for address space overflow
2017-03-14 10:50 ` Tristan Gingold
@ 2017-03-14 12:17 ` Alan Modra
2017-03-14 13:56 ` Tristan Gingold
0 siblings, 1 reply; 14+ messages in thread
From: Alan Modra @ 2017-03-14 12:17 UTC (permalink / raw)
To: Tristan Gingold; +Cc: H.J. Lu, binutils
On Tue, Mar 14, 2017 at 11:50:27AM +0100, Tristan Gingold wrote:
>
> > On 14 Mar 2017, at 11:19, Alan Modra <amodra@gmail.com> wrote:
> > The new testcases need some tweaking too. Even after applying the
> > above I'm left with:
> >
> > arm-aout +FAIL: section size overflow
> > arm-coff +FAIL: section size overflow
> > arm-epoc-pe +FAIL: section size overflow
> > arm-pe +FAIL: section size overflow
> > arm-symbianelf +FAIL: section size overflow
> > arm-wince-pe +FAIL: section size overflow
> > i386-linuxaout +FAIL: section size overflow
> > i386-linuxaout +FAIL: section size overflow
> > i386-lynxos +FAIL: section size overflow
> > i386-netware +FAIL: section size overflow
> > i586-aout +FAIL: section size overflow
> > i686-pe +FAIL: section size overflow
>
> What is the host ? 32 bit or 64 bit ?
64 bit. x86_64-linux.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Patch] ld: check for address space overflow
2017-03-14 12:17 ` Alan Modra
@ 2017-03-14 13:56 ` Tristan Gingold
2017-03-15 1:11 ` Alan Modra
0 siblings, 1 reply; 14+ messages in thread
From: Tristan Gingold @ 2017-03-14 13:56 UTC (permalink / raw)
To: Alan Modra; +Cc: H.J. Lu, binutils
> On 14 Mar 2017, at 13:17, Alan Modra <amodra@gmail.com> wrote:
>
> On Tue, Mar 14, 2017 at 11:50:27AM +0100, Tristan Gingold wrote:
>>
>>> On 14 Mar 2017, at 11:19, Alan Modra <amodra@gmail.com> wrote:
>>> The new testcases need some tweaking too. Even after applying the
>>> above I'm left with:
>>>
>>> arm-aout +FAIL: section size overflow
>>> arm-coff +FAIL: section size overflow
>>> arm-epoc-pe +FAIL: section size overflow
>>> arm-pe +FAIL: section size overflow
>>> arm-symbianelf +FAIL: section size overflow
>>> arm-wince-pe +FAIL: section size overflow
>>> i386-linuxaout +FAIL: section size overflow
>>> i386-linuxaout +FAIL: section size overflow
>>> i386-lynxos +FAIL: section size overflow
>>> i386-netware +FAIL: section size overflow
>>> i586-aout +FAIL: section size overflow
>>> i686-pe +FAIL: section size overflow
>>
>> What is the host ? 32 bit or 64 bit ?
>
> 64 bit. x86_64-linux.
Would that be ok ?
(No need to bother with additional sections).
Tristan.
commit 6e31e599777fb6a9e09f06b2fc957201b2c7eb4f
Author: Tristan Gingold <gingold@adacore.com>
Date: Tue Mar 14 14:54:37 2017 +0100
ld-checks: tweak overflow checks.
* testsuite/ld-checks/checks.exp (overflow_check): Disable for
non-elf targets.
diff --git a/ld/ChangeLog b/ld/ChangeLog
index c164710..c988c3b 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,8 @@
+2017-03-14 Tristan Gingold <gingold@adacore.com>
+
+ * testsuite/ld-checks/checks.exp (overflow_check): Disable for
+ non-elf targets.
+
2017-03-13 Tristan Gingold <gingold@adacore.com>
* ldlang.c (lang_check_section_addresses): Check for address space
diff --git a/ld/testsuite/ld-checks/checks.exp b/ld/testsuite/ld-checks/checks.exp
index 782f50a..e411d03 100644
--- a/ld/testsuite/ld-checks/checks.exp
+++ b/ld/testsuite/ld-checks/checks.exp
@@ -85,6 +85,9 @@ proc overflow_check {} {
&& ![istarget arm*-*-*] } {
return
}
+ if ![is_elf_format] {
+ return
+ }
run_dump_test "over"
run_dump_test "over2"
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Patch] ld: check for address space overflow
2017-03-14 8:15 ` Tristan Gingold
2017-03-14 10:20 ` Alan Modra
@ 2017-03-14 16:13 ` H.J. Lu
1 sibling, 0 replies; 14+ messages in thread
From: H.J. Lu @ 2017-03-14 16:13 UTC (permalink / raw)
To: Tristan Gingold; +Cc: binutils
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Patch] ld: check for address space overflow
2017-03-14 13:56 ` Tristan Gingold
@ 2017-03-15 1:11 ` Alan Modra
2017-03-15 9:26 ` Tristan Gingold
0 siblings, 1 reply; 14+ messages in thread
From: Alan Modra @ 2017-03-15 1:11 UTC (permalink / raw)
To: Tristan Gingold; +Cc: H.J. Lu, binutils
On Tue, Mar 14, 2017 at 02:56:18PM +0100, Tristan Gingold wrote:
> * testsuite/ld-checks/checks.exp (overflow_check): Disable for
> non-elf targets.
OK. I'm going to commit the following too. h8300 and ip2k targets
use a 16-bit address cpu by default, so hit the address wrap check
(more than once) on the 64k section test.
* testsuite/ld-elf/sec64k.exp: Don't run on h8300 and ip2k.
diff --git a/ld/testsuite/ld-elf/sec64k.exp b/ld/testsuite/ld-elf/sec64k.exp
index 249a909..3bf0c52 100644
--- a/ld/testsuite/ld-elf/sec64k.exp
+++ b/ld/testsuite/ld-elf/sec64k.exp
@@ -36,8 +36,10 @@ if { [istarget "d30v-*-*"]
return
}
-# ft32, m68hc11, m68hc12 and xgate run out of address space.
-if { [istarget "ft32-*-*"]
+# ft32, h8300, ip2k, m68hc11, m68hc12 and xgate run out of address space.
+if {[istarget "ft32-*-*"]
+ || [istarget "h8300-*-*"]
+ || [istarget "ip2k-*-*"]
|| [istarget "m68hc1*-*"]
|| [istarget "xgate-*"] } {
return
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Patch] ld: check for address space overflow
2017-03-15 1:11 ` Alan Modra
@ 2017-03-15 9:26 ` Tristan Gingold
0 siblings, 0 replies; 14+ messages in thread
From: Tristan Gingold @ 2017-03-15 9:26 UTC (permalink / raw)
To: Alan Modra; +Cc: H.J. Lu, binutils
> On 15 Mar 2017, at 02:11, Alan Modra <amodra@gmail.com> wrote:
>
> On Tue, Mar 14, 2017 at 02:56:18PM +0100, Tristan Gingold wrote:
>> * testsuite/ld-checks/checks.exp (overflow_check): Disable for
>> non-elf targets.
>
> OK.
Thanks, committed.
> I'm going to commit the following too. h8300 and ip2k targets
> use a 16-bit address cpu by default, so hit the address wrap check
> (more than once) on the 64k section test.
>
> * testsuite/ld-elf/sec64k.exp: Don't run on h8300 and ip2k.
Thank you for the head-up.
Maybe the overflow check should also check that the length is not larger than the address space (otherwise it could have missed these h8300 and ip2k cases), but I think this is a too artificial case.
Tristan.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2017-03-15 9:26 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-10 14:29 [Patch] ld: check for address space overflow Tristan Gingold
2017-03-11 1:14 ` Alan Modra
2017-03-13 9:47 ` Tristan Gingold
2017-03-13 17:52 ` H.J. Lu
2017-03-13 19:06 ` H.J. Lu
2017-03-13 19:27 ` H.J. Lu
2017-03-14 8:15 ` Tristan Gingold
2017-03-14 10:20 ` Alan Modra
2017-03-14 10:50 ` Tristan Gingold
2017-03-14 12:17 ` Alan Modra
2017-03-14 13:56 ` Tristan Gingold
2017-03-15 1:11 ` Alan Modra
2017-03-15 9:26 ` Tristan Gingold
2017-03-14 16:13 ` H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).