Skip to content

Commit 828a542

Browse files
HarveyHuntralfbaechle
authored andcommitted
MIPS: tools: Fix relocs tool compiler warnings
When using clang as HOSTCC, the following warnings appear: In file included from arch/mips/boot/tools/relocs_64.c:27:0: arch/mips/boot/tools/relocs.c: In function ‘read_relocs’: arch/mips/boot/tools/relocs.c:397:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] ELF_R_SYM(rel->r_info) = elf32_to_cpu(ELF_R_SYM(rel->r_info)); ^~~~~~~~~ arch/mips/boot/tools/relocs.c:397:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] arch/mips/boot/tools/relocs.c: In function ‘walk_relocs’: arch/mips/boot/tools/relocs.c:491:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] Elf_Sym *sym = &sh_symtab[ELF_R_SYM(rel->r_info)]; ^~~~~~~ arch/mips/boot/tools/relocs.c: In function ‘do_reloc’: arch/mips/boot/tools/relocs.c:502:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] unsigned r_type = ELF_R_TYPE(rel->r_info); ^~~~~~~~ arch/mips/boot/tools/relocs.c: In function ‘do_reloc_info’: arch/mips/boot/tools/relocs.c:641:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] rel_type(ELF_R_TYPE(rel->r_info)), ^~~~~~~~ Fix them by making Elf64_Mips_Rela a union Signed-off-by: Harvey Hunt <harvey.hunt@imgtec.com> Acked-by: Matt Redfearn <matt.redfearn@imgtec.com> Cc: linux-mips@linux-mips.org Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/13683/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent b73989d commit 828a542

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

arch/mips/boot/tools/relocs_64.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@
99

1010
typedef uint8_t Elf64_Byte;
1111

12-
typedef struct {
13-
Elf64_Word r_sym; /* Symbol index. */
14-
Elf64_Byte r_ssym; /* Special symbol. */
15-
Elf64_Byte r_type3; /* Third relocation. */
16-
Elf64_Byte r_type2; /* Second relocation. */
17-
Elf64_Byte r_type; /* First relocation. */
12+
typedef union {
13+
struct {
14+
Elf64_Word r_sym; /* Symbol index. */
15+
Elf64_Byte r_ssym; /* Special symbol. */
16+
Elf64_Byte r_type3; /* Third relocation. */
17+
Elf64_Byte r_type2; /* Second relocation. */
18+
Elf64_Byte r_type; /* First relocation. */
19+
} fields;
20+
Elf64_Xword unused;
1821
} Elf64_Mips_Rela;
1922

2023
#define ELF_CLASS ELFCLASS64
21-
#define ELF_R_SYM(val) (((Elf64_Mips_Rela *)(&val))->r_sym)
22-
#define ELF_R_TYPE(val) (((Elf64_Mips_Rela *)(&val))->r_type)
24+
#define ELF_R_SYM(val) (((Elf64_Mips_Rela *)(&val))->fields.r_sym)
25+
#define ELF_R_TYPE(val) (((Elf64_Mips_Rela *)(&val))->fields.r_type)
2326
#define ELF_ST_TYPE(o) ELF64_ST_TYPE(o)
2427
#define ELF_ST_BIND(o) ELF64_ST_BIND(o)
2528
#define ELF_ST_VISIBILITY(o) ELF64_ST_VISIBILITY(o)

0 commit comments

Comments
 (0)