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]

Broken Code in gas/symbols.c


Hi,

I was going over some of the binutils 2.15 code when I came across the following code :

<snip: gas/symbols.c>

void
symbol_mark_used_in_reloc (symbolS *s)
{
   if (LOCAL_SYMBOL_CHECK (s))
       s = local_symbol_convert ((struct local_symbol *) s);
   s->sy_used_in_reloc = 1;
}

</snip: gas/symbols.c>

Now local_symbol_convert creates a 'struct symbol' from a 'struct local_symbol' by doing a malloc. Since the function takes the pointer to a 'struct symbol', the newly created 'struct local symbol' does not get returned to the calling function.

The two options to make the newly created 'struct local symbol' available to the caller is either returning the value of the 'struct local symbol' or passing the 'struct symbol' by reference. The former would tend to break the consistency between all the functions defined in symbols.c as some of the functions already return values of their own. This leaves us with the second option of passing the 'struct symbol' by reference for all the functions in gas/symbols.c. For example the function symbol_mark_used_in_reloc would be changed to:

</snip: gas/symbols.h>

extern void symbol_mark_used_in_reloc (symbolS **);

</snip: gas/symbols.h>



<snip: gas/symbols.c>

void
symbol_mark_used_in_reloc (symbolS **s)
{
   symbolS *t = *s;

   if (LOCAL_SYMBOL_CHECK (t))
       t = local_symbol_convert ((struct local_symbol *) t);
   t->sy_used_in_reloc = 1;
   *s = t;
}

</snip: gas/symbols.c>

When I built the 2.15 sources for an arc-elf32 target I got the following problem:

<snip>

ravi@firebolt:/overflow/crap/tests$ cat test.s

.section .rodata.str, "aMS", @progbits, 1
.LC3: .string "main"
.section .text
mov r0, .LC3+1



ravi@firebolt:/overflow/crap/tests$ /overflow/crap/install/bin/arc-elf32-as test.s
Segmentation fault
ravi@firebolt:/overflow/crap/tests$


</snip>

My solution seems to solve this problem. Is this the best way of going about it though ?



Regards,
Ravi Ramaseshan.


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