All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] relocate-rela: use compiler.h endian macros
@ 2016-12-11  3:51 Jonathan Gray
  2016-12-24  6:05 ` Jonathan Gray
  2016-12-27 22:56 ` [U-Boot] " Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Jonathan Gray @ 2016-12-11  3:51 UTC (permalink / raw)
  To: u-boot

Use the endian macros from u-boot's compiler.h instead of duplicating
the definitions.

This also avoids a build error on OpenBSD by removing swap64 which
collides with a system definition in endian.h pulled in by inttypes.h.

Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
---
 tools/relocate-rela.c | 41 ++++-------------------------------------
 1 file changed, 4 insertions(+), 37 deletions(-)

diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c
index 670b9fd..3c9d134 100644
--- a/tools/relocate-rela.c
+++ b/tools/relocate-rela.c
@@ -15,6 +15,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include "compiler.h"
 
 #ifndef R_AARCH64_RELATIVE
 #define R_AARCH64_RELATIVE	1027
@@ -50,40 +51,6 @@ static bool supported_rela(Elf64_Rela *rela)
 	}
 }
 
-static inline uint64_t swap64(uint64_t val)
-{
-	return ((val >> 56) & 0x00000000000000ffULL) |
-	       ((val >> 40) & 0x000000000000ff00ULL) |
-	       ((val >> 24) & 0x0000000000ff0000ULL) |
-	       ((val >>  8) & 0x00000000ff000000ULL) |
-	       ((val <<  8) & 0x000000ff00000000ULL) |
-	       ((val << 24) & 0x0000ff0000000000ULL) |
-	       ((val << 40) & 0x00ff000000000000ULL) |
-	       ((val << 56) & 0xff00000000000000ULL);
-}
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-static inline uint64_t be64(uint64_t val)
-{
-	return swap64(val);
-}
-
-static inline uint64_t le64(uint64_t val)
-{
-	return val;
-}
-#else
-static inline uint64_t le64(uint64_t val)
-{
-	return swap64(val);
-}
-
-static inline uint64_t be64(uint64_t val)
-{
-	return val;
-}
-#endif
-
 static bool read_num(const char *str, uint64_t *num)
 {
 	char *endptr;
@@ -148,9 +115,9 @@ int main(int argc, char **argv)
 			return 4;
 		}
 
-		swrela.r_offset = le64(rela.r_offset);
-		swrela.r_info = le64(rela.r_info);
-		swrela.r_addend = le64(rela.r_addend);
+		swrela.r_offset = cpu_to_le64(rela.r_offset);
+		swrela.r_info = cpu_to_le64(rela.r_info);
+		swrela.r_addend = cpu_to_le64(rela.r_addend);
 
 		if (!supported_rela(&swrela))
 			continue;
-- 
2.10.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] relocate-rela: use compiler.h endian macros
  2016-12-11  3:51 [U-Boot] [PATCH] relocate-rela: use compiler.h endian macros Jonathan Gray
@ 2016-12-24  6:05 ` Jonathan Gray
  2016-12-27 22:56 ` [U-Boot] " Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Gray @ 2016-12-24  6:05 UTC (permalink / raw)
  To: u-boot

Any objections to this?

On Sun, Dec 11, 2016 at 02:51:13PM +1100, Jonathan Gray wrote:
> Use the endian macros from u-boot's compiler.h instead of duplicating
> the definitions.
> 
> This also avoids a build error on OpenBSD by removing swap64 which
> collides with a system definition in endian.h pulled in by inttypes.h.
> 
> Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
> ---
>  tools/relocate-rela.c | 41 ++++-------------------------------------
>  1 file changed, 4 insertions(+), 37 deletions(-)
> 
> diff --git a/tools/relocate-rela.c b/tools/relocate-rela.c
> index 670b9fd..3c9d134 100644
> --- a/tools/relocate-rela.c
> +++ b/tools/relocate-rela.c
> @@ -15,6 +15,7 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> +#include "compiler.h"
>  
>  #ifndef R_AARCH64_RELATIVE
>  #define R_AARCH64_RELATIVE	1027
> @@ -50,40 +51,6 @@ static bool supported_rela(Elf64_Rela *rela)
>  	}
>  }
>  
> -static inline uint64_t swap64(uint64_t val)
> -{
> -	return ((val >> 56) & 0x00000000000000ffULL) |
> -	       ((val >> 40) & 0x000000000000ff00ULL) |
> -	       ((val >> 24) & 0x0000000000ff0000ULL) |
> -	       ((val >>  8) & 0x00000000ff000000ULL) |
> -	       ((val <<  8) & 0x000000ff00000000ULL) |
> -	       ((val << 24) & 0x0000ff0000000000ULL) |
> -	       ((val << 40) & 0x00ff000000000000ULL) |
> -	       ((val << 56) & 0xff00000000000000ULL);
> -}
> -
> -#if __BYTE_ORDER == __LITTLE_ENDIAN
> -static inline uint64_t be64(uint64_t val)
> -{
> -	return swap64(val);
> -}
> -
> -static inline uint64_t le64(uint64_t val)
> -{
> -	return val;
> -}
> -#else
> -static inline uint64_t le64(uint64_t val)
> -{
> -	return swap64(val);
> -}
> -
> -static inline uint64_t be64(uint64_t val)
> -{
> -	return val;
> -}
> -#endif
> -
>  static bool read_num(const char *str, uint64_t *num)
>  {
>  	char *endptr;
> @@ -148,9 +115,9 @@ int main(int argc, char **argv)
>  			return 4;
>  		}
>  
> -		swrela.r_offset = le64(rela.r_offset);
> -		swrela.r_info = le64(rela.r_info);
> -		swrela.r_addend = le64(rela.r_addend);
> +		swrela.r_offset = cpu_to_le64(rela.r_offset);
> +		swrela.r_info = cpu_to_le64(rela.r_info);
> +		swrela.r_addend = cpu_to_le64(rela.r_addend);
>  
>  		if (!supported_rela(&swrela))
>  			continue;
> -- 
> 2.10.2
> 
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] relocate-rela: use compiler.h endian macros
  2016-12-11  3:51 [U-Boot] [PATCH] relocate-rela: use compiler.h endian macros Jonathan Gray
  2016-12-24  6:05 ` Jonathan Gray
@ 2016-12-27 22:56 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2016-12-27 22:56 UTC (permalink / raw)
  To: u-boot

On Sun, Dec 11, 2016 at 02:51:13PM +1100, Jonathan Gray wrote:

> Use the endian macros from u-boot's compiler.h instead of duplicating
> the definitions.
> 
> This also avoids a build error on OpenBSD by removing swap64 which
> collides with a system definition in endian.h pulled in by inttypes.h.
> 
> Signed-off-by: Jonathan Gray <jsg@jsg.id.au>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161227/5f2b82a1/attachment.sig>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-12-27 22:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-11  3:51 [U-Boot] [PATCH] relocate-rela: use compiler.h endian macros Jonathan Gray
2016-12-24  6:05 ` Jonathan Gray
2016-12-27 22:56 ` [U-Boot] " Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.