This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ld ALIGN


The new dlx target has an "interesting" linker script, resulting in
ld testsuite failures.  Note the ALIGNs.  

$ ./ld-new --verbose -t -o tmpdir/asm.x --check-sections tmpdir/asm.o
GNU ld version 2.13.90 20020812
  Supported emulations:
   elf32_dlx
using internal linker script:
==================================================
/* Default linker script, for normal executables */
OUTPUT_FORMAT("elf32-dlx", "",
              "")
OUTPUT_ARCH(dlx)
SEARCH_DIR("/usr/local/dlx-elf/lib");
SECTIONS
{
  . = 0;
  .text :
  {
    CREATE_OBJECT_SYMBOLS
    *(.text)
    etext = ALIGN(0);
  }
  . = ALIGN(0);
  .data :
  {
    *(.data)
    CONSTRUCTORS
    edata  =  .;
  }
  .bss :
  {
   *(.bss)
   *(COMMON)
   end = . ;
  }
}


==================================================
./ld-new: mode elf32_dlx
attempt to open tmpdir/asm.o succeeded
tmpdir/asm.o
./ld-new: section .data [00000000 -> 00000003] overlaps section .text [00000000 -> 00000003]

This patch fixes the faulty TARGET_PAGE_SIZE responsible for the
above, and provides a new "align_n" function that's a bit safer
than the old ALIGN_N macro.  As a side benefit, ALIGN in ld scripts
can now handle alignments to arbitrary boundaries.

ld/ChangeLog
	* emulparams/elf32_dlx.sh (TARGET_PAGE_SIZE): Set to 1.
	(MAXPAGESIZE): Set to 1.

	* ld.h (ALIGN_N): Delete.
	* ldexp.h (align_n): Declare.
	* ldexp.c (align_n): New function.
	(fold_binary): Use align_n instead of ALIGN_N.
	(exp_fold_tree): Likewise.
	* ldlang.c (lang_size_sections_1): Likewise.
	(lang_one_common): Likewise.

Index: ld/ld.h
===================================================================
RCS file: /cvs/src/src/ld/ld.h,v
retrieving revision 1.17
diff -u -p -r1.17 ld.h
--- ld/ld.h	3 May 2002 13:48:55 -0000	1.17
+++ ld/ld.h	13 Aug 2002 02:00:01 -0000
@@ -91,14 +91,6 @@ typedef struct user_section_struct {
 #define LONG_SIZE	(4)
 #define QUAD_SIZE	(8)
 
-/* ALIGN macro changed to ALIGN_N to avoid	*/
-/* conflict in /usr/include/machine/machparam.h */
-/* WARNING: If THIS is a 64 bit address and BOUNDARY is a 32 bit int,
-   you must coerce boundary to the same type as THIS.
-   ??? Is there a portable way to avoid this.  */
-#define ALIGN_N(this, boundary) \
-  ((( (this) + ((boundary) -1)) & (~((boundary)-1))))
-
 typedef struct {
   /* 1 => assign space to common symbols even if `relocatable_output'.  */
   boolean force_common_definition;
Index: ld/ldexp.c
===================================================================
RCS file: /cvs/src/src/ld/ldexp.c,v
retrieving revision 1.16
diff -u -p -r1.16 ldexp.c
--- ld/ldexp.c	8 Jun 2002 07:39:45 -0000	1.16
+++ ld/ldexp.c	13 Aug 2002 02:00:02 -0000
@@ -350,7 +350,7 @@ fold_binary (tree, current_section, allo
 		{
 		  bfd_vma maxpage = result.value;
 
-		  result.value = ALIGN_N (dot, maxpage);
+		  result.value = align_n (dot, maxpage);
 		  if (exp_data_seg.phase != exp_dataseg_adjust)
 		    {
 		      result.value += dot & (maxpage - 1);
@@ -593,14 +593,14 @@ exp_fold_tree (tree, current_section, al
 	    {
 	    case ALIGN_K:
 	      if (allocation_done != lang_first_phase_enum)
-		result = new_rel_from_section (ALIGN_N (dot, result.value),
+		result = new_rel_from_section (align_n (dot, result.value),
 					       current_section);
 	      else
 		result.valid_p = false;
 	      break;
 
 	    case ABSOLUTE:
-	      if (allocation_done != lang_first_phase_enum && result.valid_p)
+	      if (allocation_done != lang_first_phase_enum)
 		{
 		  result.value += result.section->bfd_section->vma;
 		  result.section = abs_output_section;
@@ -629,7 +629,7 @@ exp_fold_tree (tree, current_section, al
 	      if (allocation_done == lang_allocating_phase_enum)
 		{
 		  make_abs (&result);
-		  result.value = ALIGN_N (dot, result.value);
+		  result.value = align_n (dot, result.value);
 		}
 	      else
 		result.valid_p = false;
@@ -1126,4 +1126,15 @@ exp_get_abs_int (tree, def, name, alloca
     einfo (_("%F%S non constant expression for %s\n"), name);
 
   return res.value;
+}
+
+bfd_vma align_n (value, align)
+     bfd_vma value;
+     bfd_vma align;
+{
+  if (align <= 1)
+    return value;
+
+  value = (value + align - 1) / align;
+  return value * align;
 }
Index: ld/ldexp.h
===================================================================
RCS file: /cvs/src/src/ld/ldexp.h,v
retrieving revision 1.7
diff -u -p -r1.7 ldexp.h
--- ld/ldexp.h	15 Feb 2002 02:11:05 -0000	1.7
+++ ld/ldexp.h	13 Aug 2002 02:00:02 -0000
@@ -122,5 +122,6 @@ int exp_get_value_int PARAMS ((etree_typ
 fill_type *exp_get_fill PARAMS ((etree_type *, fill_type *, char *,
 				 lang_phase_type));
 bfd_vma exp_get_abs_int PARAMS ((etree_type *, int, char *, lang_phase_type));
+bfd_vma align_n PARAMS ((bfd_vma, bfd_vma));
 
 #endif
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.95
diff -u -p -r1.95 ldlang.c
--- ld/ldlang.c	8 Aug 2002 03:50:17 -0000	1.95
+++ ld/ldlang.c	13 Aug 2002 02:00:06 -0000
@@ -3047,9 +3047,8 @@ lang_size_sections_1 (s, output_section_
 
 	    /* Put the section within the requested block size, or
 	       align at the block boundary.  */
-	    after = ALIGN_N (os->bfd_section->vma
+	    after = align_n (os->bfd_section->vma
 			     + os->bfd_section->_raw_size / opb,
-			     /* The coercion here is important, see ld.h.  */
 			     (bfd_vma) os->block_value);
 
 	    if (bfd_is_abs_section (os->bfd_section))
@@ -3748,8 +3747,8 @@ lang_one_common (h, info)
   section = h->u.c.p->section;
 
   /* Increase the size of the section.  */
-  section->_cooked_size = ALIGN_N ((section->_cooked_size + opb - 1) / opb,
-				   (bfd_size_type) (1 << power_of_two)) * opb;
+  section->_cooked_size = align_n ((section->_cooked_size + opb - 1) / opb,
+				   (bfd_vma) 1 << power_of_two) * opb;
 
   /* Adjust the alignment if necessary.  */
   if (power_of_two > section->alignment_power)
Index: ld/emulparams/elf32_dlx.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf32_dlx.sh,v
retrieving revision 1.1
diff -u -p -r1.1 elf32_dlx.sh
--- ld/emulparams/elf32_dlx.sh	28 May 2002 14:08:38 -0000	1.1
+++ ld/emulparams/elf32_dlx.sh	13 Aug 2002 02:00:06 -0000
@@ -4,6 +4,6 @@ OUTPUT_FORMAT="elf32-dlx"
 ARCH=dlx
 MACHINE=
 TEXT_START_ADDR=0
-TARGET_PAGE_SIZE=0
+TARGET_PAGE_SIZE=1
 EMBEDDED=yes
-MAXPAGESIZE=0
+MAXPAGESIZE=1

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]