public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [ld]: Checks for address space overflow will reject any avr program.
@ 2017-03-14 11:01 Georg-Johann Lay
  2017-03-14 11:16 ` Tristan Gingold
  0 siblings, 1 reply; 4+ messages in thread
From: Georg-Johann Lay @ 2017-03-14 11:01 UTC (permalink / raw)
  To: binutils; +Cc: Senthil Kumar Selvaraj, Tristan Gingold

Hi Tristan.

Your addition to ld/ldlang.c::lang_check_section_addresses() leads
to rejection of any program by ld, for example

int x;

int main (void)
{
     return 0;
}

And compiled with

$ avr-gcc-7 main.c -Os -mmcu=atmega8 -save-temps

/INSTALL/bin/../lib/gcc/avr/7.0.1/../../../../avr/bin/ld: section .data 
VMA wraps around address space
/INSTALL/bin/../lib/gcc/avr/7.0.1/../../../../avr/bin/ld: section .bss 
VMA wraps around address space
collect2: error: ld returned 1 exit status

The generated asm is (effectively):

	.file	"main.c"
	.section	.text.startup,"ax",@progbits
.global	main
	.type	main, @function
main:
	ldi r25,0
	ldi r24,0
	ret
	.size	main, .-main
	.comm	x,2,1
	.ident	"GCC: (GNU) 7.0.1 20170314 (experimental) [trunk revision 244001]"


I didn't actually check whether it's due to your change, but as
you are active there, you'll likely know the solution.

avr is using virtual addresses in order to linearize the address
space.


If there is no obvious solution to fix this for avr, it would be
highly appreciated to have a configure option so that respective
portions of ld sources can be deactivated.

If you need more information to reproduce the issue, please let
me know.


Johann


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ld]: Checks for address space overflow will reject any avr program.
  2017-03-14 11:01 [ld]: Checks for address space overflow will reject any avr program Georg-Johann Lay
@ 2017-03-14 11:16 ` Tristan Gingold
  2017-03-14 11:52   ` Tristan Gingold
  0 siblings, 1 reply; 4+ messages in thread
From: Tristan Gingold @ 2017-03-14 11:16 UTC (permalink / raw)
  To: Georg-Johann Lay; +Cc: binutils, Senthil Kumar Selvaraj

[...]

> I didn't actually check whether it's due to your change, but as
> you are active there, you'll likely know the solution.
> 
> avr is using virtual addresses in order to linearize the address
> space.

Yes, I suppose that section offset is larger than address space.

I think I have an idea for this.

Tristan.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ld]: Checks for address space overflow will reject any avr program.
  2017-03-14 11:16 ` Tristan Gingold
@ 2017-03-14 11:52   ` Tristan Gingold
  2017-03-15 10:24     ` Georg-Johann Lay
  0 siblings, 1 reply; 4+ messages in thread
From: Tristan Gingold @ 2017-03-14 11:52 UTC (permalink / raw)
  To: Georg-Johann Lay; +Cc: binutils, Senthil Kumar Selvaraj


> On 14 Mar 2017, at 12:16, Tristan Gingold <gingold@adacore.com> wrote:
> 
> [...]
> 
>> I didn't actually check whether it's due to your change, but as
>> you are active there, you'll likely know the solution.
>> 
>> avr is using virtual addresses in order to linearize the address
>> space.
> 
> Yes, I suppose that section offset is larger than address space.
> 
> I think I have an idea for this.

Does this work for you ?

Tristan.

diff --git a/ld/ldlang.c b/ld/ldlang.c
index a0638ea..cf7aadc 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -4782,16 +4782,23 @@ lang_check_section_addresses (void)
   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
+      /* Only for allocated sections and if already in the address space.
+	 This handles targets like avr which have I+D small spaces linearized
+	 in the only one ELF address space.  */
+      if ((s->flags & SEC_ALLOC) != 0
+	  && (s->vma & addr_mask) == s->vma)
 	{
-	  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_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);
+	    }
 	}
     }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ld]: Checks for address space overflow will reject any avr program.
  2017-03-14 11:52   ` Tristan Gingold
@ 2017-03-15 10:24     ` Georg-Johann Lay
  0 siblings, 0 replies; 4+ messages in thread
From: Georg-Johann Lay @ 2017-03-15 10:24 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils, Senthil Kumar Selvaraj

On 14.03.2017 12:52, Tristan Gingold wrote:
>
>> On 14 Mar 2017, at 12:16, Tristan Gingold <gingold@adacore.com> wrote:
>>
>> [...]
>>
>>> I didn't actually check whether it's due to your change, but as
>>> you are active there, you'll likely know the solution.
>>>
>>> avr is using virtual addresses in order to linearize the address
>>> space.
>>
>> Yes, I suppose that section offset is larger than address space.
>>
>> I think I have an idea for this.
>
> Does this work for you ?
>
> Tristan.
>
> diff --git a/ld/ldlang.c b/ld/ldlang.c
> index a0638ea..cf7aadc 100644
> --- a/ld/ldlang.c
> +++ b/ld/ldlang.c
> @@ -4782,16 +4782,23 @@ lang_check_section_addresses (void)
>    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
> +      /* Only for allocated sections and if already in the address space.
> +	 This handles targets like avr which have I+D small spaces linearized
> +	 in the only one ELF address space.  */
> +      if ((s->flags & SEC_ALLOC) != 0
> +	  && (s->vma & addr_mask) == s->vma)
>  	{
> -	  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_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);
> +	    }
>  	}
>      }
>

I tried this patch with some simple programs and it worked for them.

Thanks for the fast fix.

Johann


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-15 10:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-14 11:01 [ld]: Checks for address space overflow will reject any avr program Georg-Johann Lay
2017-03-14 11:16 ` Tristan Gingold
2017-03-14 11:52   ` Tristan Gingold
2017-03-15 10:24     ` Georg-Johann Lay

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).