public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: Bug in ARM linker...
@ 1999-11-24  3:01 Nick Clifton
  1999-11-24 10:45 ` Scott Bambrough
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Clifton @ 1999-11-24  3:01 UTC (permalink / raw)
  To: ian; +Cc: scottb, pb, patb, binutils

Hi Guys,

:    These 3 sections all share the SAME output section.  I think this is the
:    root cause of the problem.  Somewhere along the way the flags for the
:    output .text section are altered by the code.  At any rate I believe
:    this is the reason why the DT_TEXTREL tag is not output in the .dynamic
:    section.  The output .text section should be readonly for ELF.
: 
: The linker script directs the linker to put the .glue sections in the
: .text section.  This is normal behaviour.
: 
: The bug is that the .glue sections are not marked SEC_READONLY, but
: presumably they should be.  See bfd_elf32_arm_get_bfd_for_interworking
: in bfd/elf32-arm.h.  Add SEC_READONLY and SEC_CODE to the flags passed
: to bfd_set_section_flags.
: 
: Nick, let me know if that seems wrong.

Nope, I think that you are absolutely right.

Scott - try this patch and let me know if it solves your problem.

Cheers
	Nick

1999-11-24  Nick Clifton  <nickc@cygnus.com>

	* elf32-arm.h (bfd_elf32_arm_get_bfd_for_interworking): Add
	SEC_CODE and SEC_READONLY flags to glue sections.

Index: bfd/elf32-arm.h
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/elf32-arm.h,v
retrieving revision 1.25
diff -p -r1.25 elf32-arm.h
*** elf32-arm.h	1999/09/17 04:03:17	1.25
--- elf32-arm.h	1999/11/24 10:59:48
*************** bfd_elf32_arm_get_bfd_for_interworking (
*** 548,554 ****
        /* Note: we do not include the flag SEC_LINKER_CREATED, as this
  	 will prevent elf_link_input_bfd() from processing the contents
  	 of this section.  */
!       flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
  
        sec = bfd_make_section (abfd, ARM2THUMB_GLUE_SECTION_NAME);
  
--- 548,554 ----
        /* Note: we do not include the flag SEC_LINKER_CREATED, as this
  	 will prevent elf_link_input_bfd() from processing the contents
  	 of this section.  */
!       flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY;
  
        sec = bfd_make_section (abfd, ARM2THUMB_GLUE_SECTION_NAME);
  
*************** bfd_elf32_arm_get_bfd_for_interworking (
*** 566,572 ****
  
    if (sec == NULL)
      {
!       flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
  
        sec = bfd_make_section (abfd, THUMB2ARM_GLUE_SECTION_NAME);
  
--- 566,572 ----
  
    if (sec == NULL)
      {
!       flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY;
  
        sec = bfd_make_section (abfd, THUMB2ARM_GLUE_SECTION_NAME);
  

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

* Re: Bug in ARM linker...
  1999-11-24  3:01 Bug in ARM linker Nick Clifton
@ 1999-11-24 10:45 ` Scott Bambrough
  1999-11-24 11:22   ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Scott Bambrough @ 1999-11-24 10:45 UTC (permalink / raw)
  To: Nick Clifton; +Cc: ian, pb, patb, binutils

[-- Attachment #1: Type: text/plain, Size: 831 bytes --]

Nick Clifton wrote:
> 
> Scott - try this patch and let me know if it solves your problem.
>

Hi Nick,

Thanks for the patch. I tried it and it solves the problem.  Should you
make a similar change in coff-arm.c as well?

I have attached a patch that incorporates yours and adds a warning when
the DT_TEXTREL tag is added to the dynamic segment.

1999-11-24  Nick Clifton  <nickc@cygnus.com>

	* elf32-arm.h (bfd_elf32_arm_get_bfd_for_interworking):  Add 
	  SEC_CODE | SEC_READONLY to flags for sections .glue_7t and
	  .glue_7.

1999-11-24  Scott Bambrough  <scottb@netwinder.org>

	* elf32-arm.h (elf32_arm_size_dynamic_sections):  Output warning
	  when DT_TEXTREL tag added to the dynamic segment.

-- 
Scott Bambrough - Software Engineer
REBEL.COM    http://www.rebel.com
NetWinder    http://www.netwinder.org
binutils.diff


[-- Attachment #2: binutils.diff --]
[-- Type: text/x-diff, Size: 1752 bytes --]

Index: bfd/elf32-arm.h
===================================================================
RCS file: /cvs/binutils/binutils/bfd/elf32-arm.h,v
retrieving revision 1.21
diff -u -p -r1.21 elf32-arm.h
--- elf32-arm.h	1999/09/17 11:04:47	1.21
+++ elf32-arm.h	1999/11/24 18:13:48
@@ -548,7 +548,7 @@ bfd_elf32_arm_get_bfd_for_interworking (
       /* Note: we do not include the flag SEC_LINKER_CREATED, as this
 	 will prevent elf_link_input_bfd() from processing the contents
 	 of this section.  */
-      flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
+      flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY;
 
       sec = bfd_make_section (abfd, ARM2THUMB_GLUE_SECTION_NAME);
 
@@ -566,7 +566,7 @@ bfd_elf32_arm_get_bfd_for_interworking (
 
   if (sec == NULL)
     {
-      flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
+      flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY;
 
       sec = bfd_make_section (abfd, THUMB2ARM_GLUE_SECTION_NAME);
 
@@ -2810,6 +2810,7 @@ elf32_arm_size_dynamic_sections (output_
 		  outname = bfd_get_section_name (output_bfd,
 						  s->output_section);
 		  target = bfd_get_section_by_name (output_bfd, outname + 4);
+		  
 		  if (target != NULL
 		      && (target->flags & SEC_READONLY) != 0
 		      && (target->flags & SEC_ALLOC) != 0)
@@ -2882,6 +2883,9 @@ elf32_arm_size_dynamic_sections (output_
 	{
 	  if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
 	    return false;
+	  _bfd_error_handler (_("\
+Warning: Relocations to fixup absolute addresses in readonly sections \
+have been included in this shared library."));
 	}
     }
 

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

* Re: Bug in ARM linker...
  1999-11-24 10:45 ` Scott Bambrough
@ 1999-11-24 11:22   ` Ian Lance Taylor
  0 siblings, 0 replies; 6+ messages in thread
From: Ian Lance Taylor @ 1999-11-24 11:22 UTC (permalink / raw)
  To: scottb; +Cc: nickc, pb, patb, binutils

   Date: Wed, 24 Nov 1999 13:41:01 -0500
   From: Scott Bambrough <scottb@netwinder.org>

   I have attached a patch that incorporates yours and adds a warning when
   the DT_TEXTREL tag is added to the dynamic segment.

I think any warning should be generic, not ARM specific, and I think
the warning should be controlled by a command line option such as the
Solaris -assert pure-text option.

Ian

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

* Re: Bug in ARM linker...
@ 1999-11-25  3:52 Nick Clifton
  0 siblings, 0 replies; 6+ messages in thread
From: Nick Clifton @ 1999-11-25  3:52 UTC (permalink / raw)
  To: scottb; +Cc: ian, pb, patb, binutils

Hi Scott,

: Thanks for the patch. I tried it and it solves the problem.  Should you
: make a similar change in coff-arm.c as well?

Yes :-)

: I have attached a patch that incorporates yours and adds a warning when
: the DT_TEXTREL tag is added to the dynamic segment.

: From: Ian Lance Taylor <ian@zembu.com>
: 
: I think any warning should be generic, not ARM specific, and I think
: the warning should be controlled by a command line option such as the
: Solaris -assert pure-text option.

I'll leave this for you two to sort out.  I have checked in the patch
to elf32-arm.h anc coff-arm.c to add the SEC_CODE and SEC_READONLY
attributes to the glue sections.

Cheers
	Nick

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

* Re: Bug in ARM linker...
  1999-11-23 15:52 Scott Bambrough
@ 1999-11-23 16:02 ` Ian Lance Taylor
  0 siblings, 0 replies; 6+ messages in thread
From: Ian Lance Taylor @ 1999-11-23 16:02 UTC (permalink / raw)
  To: scottb; +Cc: nickc, pb, patb, binutils

   Date: Tue, 23 Nov 1999 18:49:08 -0500
   From: Scott Bambrough <scottb@netwinder.org>

   These 3 sections all share the SAME output section.  I think this is the
   root cause of the problem.  Somewhere along the way the flags for the
   output .text section are altered by the code.  At any rate I believe
   this is the reason why the DT_TEXTREL tag is not output in the .dynamic
   section.  The output .text section should be readonly for ELF.

The linker script directs the linker to put the .glue sections in the
.text section.  This is normal behaviour.

The bug is that the .glue sections are not marked SEC_READONLY, but
presumably they should be.  See bfd_elf32_arm_get_bfd_for_interworking
in bfd/elf32-arm.h.  Add SEC_READONLY and SEC_CODE to the flags passed
to bfd_set_section_flags.

Nick, let me know if that seems wrong.

Ian

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

* Bug in ARM linker...
@ 1999-11-23 15:52 Scott Bambrough
  1999-11-23 16:02 ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Scott Bambrough @ 1999-11-23 15:52 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Philip Blundell, patb, binutils mailing list

Hi Nick,

I have found a bug in the ARM linker, and I think you might be able to
help me. 

The problem is the DT_TEXTREL tag is not being written out to a shared
library.  This is due to the fact the SEC_READONLY flag is not set on
the .text section.  See elf32_arm_size_dynamic_relocs() in elf32-arm.h. 
The test is around line 2817 I believe.  A search for DT_TEXTREL in the
file will turn it up quickly.

I believe I have tracked the problem down to ld/ldlang.c:wild_doit(). 
The statement at line 1165 clears the SEC_READONLY flag in the output
section because the input section does not have it set.

This routine takes asection* as a parameter and is called in a loop
through a list of input sections.  If I break in the loop and examine
each section I eventually see a section with the following attributes:

section->name = .text
section->flags = 0x237
section->output_section = 0x207548c
section->output_section->name = .text
section->output_section->flags = 0x237

The next section has the following attributes:

section->name = .glue_7t
section->flags = 0x20203
section->output_section = 0x207548c
section->output_section->name = .text
section->output_section->flags = 0x237

The next section has the following attributes:

section->name = .glue_7
section->flags = 0x20203
section->output_section = 0x207548c
section->output_section->name = .text
section->output_section->flags = 0x20227

These 3 sections all share the SAME output section.  I think this is the
root cause of the problem.  Somewhere along the way the flags for the
output .text section are altered by the code.  At any rate I believe
this is the reason why the DT_TEXTREL tag is not output in the .dynamic
section.  The output .text section should be readonly for ELF.

I believe these sections are for the ARM-Thumb interwork code, and their
contents should be output to the .text section.  I'm not familiar with
the Thumb code, so I'd appreciate a little help if you have time.

Scott

-- 
Scott Bambrough - Software Engineer
REBEL.COM    http://www.rebel.com
NetWinder    http://www.netwinder.org

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

end of thread, other threads:[~1999-11-25  3:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-24  3:01 Bug in ARM linker Nick Clifton
1999-11-24 10:45 ` Scott Bambrough
1999-11-24 11:22   ` Ian Lance Taylor
  -- strict thread matches above, loose matches on Subject: below --
1999-11-25  3:52 Nick Clifton
1999-11-23 15:52 Scott Bambrough
1999-11-23 16:02 ` Ian Lance Taylor

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