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]

Re: Strange code in tc-mips.c


Thiemo Seufer <ica2_ts@csv.ica.uni-stuttgart.de> writes:

> while figuring out what's the use of mips_64 in tc-mips.c I found
> this gem:
> 
> void
> cons_fix_new_mips (frag, where, nbytes, exp)
>      fragS *frag ATTRIBUTE_UNUSED;
>      int where;
>      unsigned int nbytes;
>      expressionS *exp;
> {
> #ifndef OBJ_ELF
>   /* If we are assembling in 32 bit mode, turn an 8 byte reloc into a
>      4 byte reloc.  */
>   if (nbytes == 8 && ! mips_64)
>     {
>       if (target_big_endian)
>         where += 4;
>       nbytes = 4;
>     }
> #endif

I wrote that code to support 64 bit targets when using a 32 bit object
file format.  64 bit code sometimes naturally uses 64 bit addresses,
particularly when the compiler uses 64 bits for pointers.  However,
the compiler was ahead of the assembler in 64 bit support.  At the
time I wrote that code, ELF support was only available for 32 bit
MIPS.  Even today, ECOFF only supports 32 bit addresses.

That put us in the position of support 64 bit code with a 32 bit
object file format.  This works fine; although the linker of course
can only place sections at addresses which can be named with 32 bits,
the addresses of those sections can be used to initialize 64 bit
pointers.

This was unquestionably a hack.  It was a way to support a 64 bit
compiler without a 64 bit object file format.  In practice this was
enough to permit people to get work done for 64 bit MIPS chips.  Now
it may be OK to delete this code, and tell people using ECOFF that
they must use ELF for 64 bit code.

> According to internals.texi, TC_CONS_FIX_NEW is used for fixups
> of data allocation pseudo-ops (like .dword).

Note that it is only used when a fixup is required.  It is not used
for constants.

> I can't see even the intention behind this:
>   - A gas with ELF _support_ never uses this code.

It did at one time.  Now that 64 bit ELF is supported, it is no longer
necessary to enable this for ELF.

>   - Without ELF support, the check goes effectively for -mabi=64,
>     not for 64bit assembly.

When I wrote the test, it might have been done unconditionally for an
8 byte relocation.  I'm not sure why it is a benefit to test !
mips_64.

>   - The code then silently discards the upper word. If larger
>     data definitions are illegal in 32bit ECOFF(?), this should
>     be checked earlier and with a warning.

I don't think the code silently discards anything.  The code is just
creating a fixup.  If this leads to discarding real data, the checks
in fixup_segment should catch that.

Ian


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