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]

.comm size problem


Hello,

I'm a bit fresh binutils programmer, so you'll all excuse me for asking many questions...

The .comm pseudo-op allocates n-bytes common area. The problem is that I dont want it to allocate n-bytes, but I want to allocate n-lwords (because of target specific reasons). What is the best approach to fix this:

a) Write my own custom, target specific .comm handler, which simply replicates the s_comm function, only multiplying its size by 4 -- storing the common symbols value with 4 times its original value in the object file.

b) Patch ld/ldlang.c (lang_one_common) to allocate times 4 bytes when it encounters a common symbol.

(BTW! All this applies to the tic4x target only.)

I like b) best, despite its global impacts compared to a), because when someone dumps an object file with nm, they will expect to get the same literal number listed on the common symbol as they have used in the source file. Another significant reason to do is this way, is because all binutils tools, e.g. objdump -h, dumps section sizes and such in terms of lwords, not bytes.

I planned on using a -DCOMMON_OCTETS_PER_BYTE definition for the tic4x target to override the default def, similar to the OBJDUMP_DEFS path I recently have committed. But I didnt find a "LD_DEFS" hook in configure.in to place this target specific definition on :( -- I was hoping things were done similar both places - but no. Can someone help me out with this? Where and how is the prefered method of placing this target specific compile definition in ld?

I have attached a possible solution, yet still incomplete. And I am *very* open to suggestions and comments.


Thanks
Svein
Index: ld/ldlang.c
===================================================================
RCS file: /prosjekt/gnu/src/src/ld/ldlang.c,v
retrieving revision 1.102
diff -c -3 -p -r1.102 ldlang.c
*** ld/ldlang.c	15 Oct 2002 00:09:02 -0000	1.102
--- ld/ldlang.c	23 Oct 2002 16:11:49 -0000
*************** lang_common ()
*** 3730,3735 ****
--- 3730,3743 ----
      }
  }
  
+ /* Common size multiplication factor.  Some targets
+    have different minimum storage units than one byte, and
+    for these targets the .comm value should refer to # units
+    not bytes. */
+ #ifndef COMMON_OCTETS_PER_BYTE
+ #define COMMON_OCTETS_PER_BYTE (1)
+ #endif
+ 
  /* Place one common symbol in the correct section.  */
  
  static boolean
*************** lang_one_common (h, info)
*** 3746,3752 ****
    if (h->type != bfd_link_hash_common)
      return true;
  
!   size = h->u.c.size;
    power_of_two = h->u.c.p->alignment_power;
  
    if (config.sort_common
--- 3754,3760 ----
    if (h->type != bfd_link_hash_common)
      return true;
  
!   size = h->u.c.size * COMMON_OCTETS_PER_BYTE;
    power_of_two = h->u.c.p->alignment_power;
  
    if (config.sort_common
*************** lang_one_common (h, info)
*** 3808,3816 ****
  
        minfo ("0x");
        if (size <= 0xffffffff)
! 	sprintf (buf, "%lx", (unsigned long) size);
        else
! 	sprintf_vma (buf, size);
        minfo ("%s", buf);
        len = strlen (buf);
  
--- 3816,3824 ----
  
        minfo ("0x");
        if (size <= 0xffffffff)
! 	sprintf (buf, "%lx", (unsigned long) size / COMMON_OCTETS_PER_BYTE );
        else
! 	sprintf_vma (buf, size / COMMON_OCTETS_PER_BYTE );
        minfo ("%s", buf);
        len = strlen (buf);
  

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