[PATCH] bfd: tweak SET_ARCH_MACH of aout-cris.c
Gunther Nikl
gnikl@justmail.de
Tue Apr 21 20:12:10 GMT 2020
Hello!
This patch changes how SET_ARCH_MACH is used. As done currently it calls the
function stored in bfd_target/_bfd_set_arch_mach directly ignoring the bfd
function parameter available at the place the macro is used. In essence this
is bfd_set_arch_mach in disguise. Using a direct call is not wrong (after all
the code was there for almost 20 years and xvec is const), nevertheless using
bfd_set_arch_mach feels to be 'more' correct. The DEFAULT_ARCH is deleted since
its only required iff SET_ARCH_MACH is not defined. I wonder what the set_sizes
method is good for if the method is not called without a bfd_set_arch_mach call?
The additional changes to the local swap_ext_reloc_in function are meant to
align it with the "base" swap_ext_reloc_in function in aoutx.h. About the
r_index casting I am not sure anymore since the commit to aoutx.h talks about
K&R. Maybe the casts in aoutx.h should be removed? The change to r_type
handling is a no-op, since the SHIFT value is 0. However for consistency I
think the code should use the same style as the base code from aoutx.h.
Regards,
Gunther Nikl
2020-04-XX Gunther Nikl <gnikl@justmail.de>
* aout-cris.c (DEFAULT_ARCH): Delete define.
(MY_set_arch_mach): Likewise.
(SET_ARCH_MACH): Use bfd_set_arch_mach with an explicit architecture
of bfd_arch_cris.
(swap_ext_reloc_in): Add casts to r_index extraction. Mask valid bits
of r_type before the shift.
-- cut --
diff --git a/bfd/aout-cris.c b/bfd/aout-cris.c
index 30ab2b5f49..e9ed050a1b 100644
--- a/bfd/aout-cris.c
+++ b/bfd/aout-cris.c
@@ -56,9 +56,6 @@
#define TARGET_PAGE_SIZE SEGMENT_SIZE
#define TARGETNAME "a.out-cris"
-/* The definition here seems not used; just provided as a convention. */
-#define DEFAULT_ARCH bfd_arch_cris
-
/* Do not "beautify" the CONCAT* macro args. Traditional C will not
remove whitespace added here, and thus will fail to concatenate
the tokens. */
@@ -92,9 +89,8 @@ static bfd_boolean MY (set_sizes) (bfd *);
through SET_ARCH_MACH. The default bfd_default_set_arch_mach will
not call set_sizes. */
-#define MY_set_arch_mach NAME (aout, set_arch_mach)
#define SET_ARCH_MACH(BFD, EXECP) \
- MY_set_arch_mach (BFD, DEFAULT_ARCH, N_MACHTYPE (EXECP))
+ bfd_set_arch_mach (BFD, bfd_arch_cris, N_MACHTYPE (EXECP))
/* These macros describe the binary layout of the reloc information we
use in a file. */
@@ -231,12 +227,12 @@ MY (swap_ext_reloc_in) (bfd *abfd,
cache_ptr->address = (GET_SWORD (abfd, bytes->r_address));
/* Now the fun stuff. */
- r_index = (bytes->r_index[2] << 16)
- | (bytes->r_index[1] << 8)
- | bytes->r_index[0];
+ r_index = (((unsigned int) bytes->r_index[2] << 16)
+ | ((unsigned int) bytes->r_index[1] << 8)
+ | bytes->r_index[0]);
r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
- r_type = ((bytes->r_type[0]) >> RELOC_EXT_BITS_TYPE_SH_LITTLE)
- & RELOC_EXT_BITS_TYPE_LITTLE;
+ r_type = ((bytes->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
+ >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
if (r_type > 2)
{
-- cut --
More information about the Binutils
mailing list