diff options
Diffstat (limited to 'gas/config/tc-bpf.c')
-rw-r--r-- | gas/config/tc-bpf.c | 77 |
1 files changed, 31 insertions, 46 deletions
diff --git a/gas/config/tc-bpf.c b/gas/config/tc-bpf.c index 84eab3f..fd77c6f 100644 --- a/gas/config/tc-bpf.c +++ b/gas/config/tc-bpf.c @@ -315,7 +315,7 @@ immediate_overflow (int64_t value, unsigned bits) long md_pcrel_from_section (fixS *fixP, segT sec) { - if (fixP->fx_addsy != (symbolS *) NULL + if (fixP->fx_addsy != NULL && (! S_IS_DEFINED (fixP->fx_addsy) || (S_GET_SEGMENT (fixP->fx_addsy) != sec) || S_IS_EXTERNAL (fixP->fx_addsy) @@ -362,7 +362,7 @@ tc_gen_reloc (asection *sec ATTRIBUTE_UNUSED, fixS *fixP) reloc->howto = bfd_reloc_type_lookup (stdoutput, r_type); - if (reloc->howto == (reloc_howto_type *) NULL) + if (reloc->howto == NULL) { as_bad_where (fixP->fx_file, fixP->fx_line, _("relocation is not supported")); @@ -516,17 +516,6 @@ encode_int32 (int32_t value, char *buffer) } } -/* Write a BPF instruction to BUF. */ - -static void -write_insn_bytes (bfd_byte *buf, char *bytes) -{ - int i; - - for (i = 0; i < 8; ++i) - md_number_to_chars ((char *) buf + i, (valueT) bytes[i], 1); -} - /* *FRAGP has been relaxed to its final size, and now needs to have the bytes inside it modified to conform to the new size. @@ -625,13 +614,14 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, { /* 16-bit disp is known and not in range. Turn the JA into a JAL with a 32-bit displacement. */ - char bytes[8] = {0}; - - bytes[0] = ((BPF_CLASS_JMP32|BPF_CODE_JA|BPF_SRC_K) >> 56) & 0xff; - bytes[1] = (word >> 48) & 0xff; - bytes[2] = 0; /* disp16 high */ - bytes[3] = 0; /* disp16 lo */ - write_insn_bytes (buf, bytes); + buf[0] = ((BPF_CLASS_JMP32|BPF_CODE_JA|BPF_SRC_K) >> 56) & 0xff; + buf[1] = (word >> 48) & 0xff; + buf[2] = 0; /* disp16 high */ + buf[3] = 0; /* disp16 lo */ + buf[4] = 0; + buf[5] = 0; + buf[6] = 0; + buf[7] = 0; /* Install fixup for the JAL. */ reloc_howto_type *reloc_howto @@ -713,8 +703,6 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, /* 16-bit disp is known and not in range. Turn the JXX into a sequence JXX +1; JA +1; JAL d32. */ - char bytes[8]; - /* First, set the 16-bit offset in the current instruction to 1. */ @@ -726,24 +714,25 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, /* Then, write the JA + 1 */ - bytes[0] = 0x05; /* JA */ - bytes[1] = 0x0; - encode_int16 (1, bytes + 2); - bytes[4] = 0x0; - bytes[5] = 0x0; - bytes[6] = 0x0; - bytes[7] = 0x0; - write_insn_bytes (buf, bytes); + buf[0] = 0x05; /* JA */ + buf[1] = 0x0; + encode_int16 (1, (char *) buf + 2); + buf[4] = 0x0; + buf[5] = 0x0; + buf[6] = 0x0; + buf[7] = 0x0; buf += 8; /* Finally, write the JAL to the target. */ - bytes[0] = ((BPF_CLASS_JMP32|BPF_CODE_JA|BPF_SRC_K) >> 56) & 0xff; - bytes[1] = 0; - bytes[2] = 0; - bytes[3] = 0; - encode_int32 ((int32_t) 0, bytes + 4); - write_insn_bytes (buf, bytes); + buf[0] = ((BPF_CLASS_JMP32|BPF_CODE_JA|BPF_SRC_K) >> 56) & 0xff; + buf[1] = 0; + buf[2] = 0; + buf[3] = 0; + buf[4] = 0; + buf[5] = 0; + buf[6] = 0; + buf[7] = 0; /* Install fixup for the JAL. */ reloc_howto_type *reloc_howto @@ -848,7 +837,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) break; } - if (fixP->fx_addsy == (symbolS *) NULL) + if (fixP->fx_addsy == NULL) fixP->fx_done = 1; if (fixP->fx_done) @@ -870,14 +859,14 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) md_number_to_chars (where, *valP, 8); break; case BFD_RELOC_BPF_DISP16: - md_number_to_chars (where + 2, (uint16_t) *valP, 2); + md_number_to_chars (where + 2, *valP, 2); break; case BFD_RELOC_BPF_DISP32: case BFD_RELOC_BPF_DISPCALL32: - md_number_to_chars (where + 4, (uint32_t) *valP, 4); + md_number_to_chars (where + 4, *valP, 4); break; case BFD_RELOC_16_PCREL: - md_number_to_chars (where + 2, (uint32_t) *valP, 2); + md_number_to_chars (where + 2, *valP, 2); break; default: as_bad_where (fixP->fx_file, fixP->fx_line, @@ -1195,13 +1184,11 @@ add_fixed_insn (struct bpf_insn *insn) { char *this_frag = frag_more (insn->size); char bytes[16]; - int i; /* First encode the known parts of the instruction, including opcodes and constant immediates, and write them to the frag. */ encode_insn (insn, bytes, 0 /* relax */); - for (i = 0; i < insn->size; ++i) - md_number_to_chars (this_frag + i, (valueT) bytes[i], 1); + memcpy (this_frag, bytes, insn->size); /* Now install the instruction fixups. */ install_insn_fixups (insn, frag_now, @@ -1214,7 +1201,6 @@ static void add_relaxed_insn (struct bpf_insn *insn, expressionS *exp) { char bytes[16]; - int i; char *this_frag; unsigned worst_case = relaxed_branch_length (NULL, NULL, 0); unsigned best_case = insn->size; @@ -1231,8 +1217,7 @@ add_relaxed_insn (struct bpf_insn *insn, expressionS *exp) /* First encode the known parts of the instruction, including opcodes and constant immediates, and write them to the frag. */ encode_insn (insn, bytes, 1 /* relax */); - for (i = 0; i < insn->size; ++i) - md_number_to_chars (this_frag + i, (valueT) bytes[i], 1); + memcpy (this_frag, bytes, insn->size); /* Note that instruction fixups will be applied once the frag is relaxed, in md_convert_frag. */ |