From ee0738df021c42217828f02858c1f882a1546557 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 16 Jun 2014 10:17:50 +0930 Subject: [PATCH] Fix uninitialised VAX insn MALLOC_PERTURB_=1 results in "FAIL: VAX ELF relocations", due to object file being emitted with uninitialised fields. Since these fields had RELA relocs the field value won't be used at final link time, so the problem is only seen in relocatable object files. This rewrite of md_apply_fix clears all fields with relocs, whereas before some fields had non-zero values. gas/ * config/tc-vax.c (md_apply_fix): Rewrite. (tc_gen_reloc, vax_cons, vax_cons_fix_new): Style: Use NO_RELOC define rather than the equivalent BFD_RELOC_NONE. gas/testsuite/ * gas/vax/elf-rel.d: Update. --- gas/ChangeLog | 6 ++++++ gas/config/tc-vax.c | 26 ++++++++++++++++---------- gas/testsuite/ChangeLog | 4 ++++ gas/testsuite/gas/vax/elf-rel.d | 8 ++++---- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/gas/ChangeLog b/gas/ChangeLog index 383393b..7f6ec03 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,5 +1,11 @@ 2014-06-16 Alan Modra + * config/tc-vax.c (md_apply_fix): Rewrite. + (tc_gen_reloc, vax_cons, vax_cons_fix_new): Style: Use NO_RELOC + define rather than the equivalent BFD_RELOC_NONE. + +2014-06-16 Alan Modra + * config/tc-arm.c (s_arm_elf_cons): Initialise after frag_more. (md_apply_fix): Delete now unnecessary zeroing for BFD_RELOC_ARM_GOT* and BFD_RELOC_ARM_TLS* relocs. Simplify BFD_RELOC_8 case. diff --git a/gas/config/tc-vax.c b/gas/config/tc-vax.c index 0740a9b..bccf596 100644 --- a/gas/config/tc-vax.c +++ b/gas/config/tc-vax.c @@ -278,15 +278,21 @@ md_apply_fix (fixS *fixP, valueT *valueP, segT seg ATTRIBUTE_UNUSED) { valueT value = * valueP; - if (((fixP->fx_addsy == NULL && fixP->fx_subsy == NULL) - && fixP->fx_r_type != BFD_RELOC_32_PLT_PCREL - && fixP->fx_r_type != BFD_RELOC_32_GOT_PCREL) - || fixP->fx_r_type == NO_RELOC) - number_to_chars_littleendian (fixP->fx_where + fixP->fx_frag->fr_literal, - value, fixP->fx_size); + if (fixP->fx_subsy != (symbolS *) NULL) + as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex")); - if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0) + if (fixP->fx_addsy == NULL) fixP->fx_done = 1; + + if (fixP->fx_done) + number_to_chars_littleendian (fixP->fx_where + fixP->fx_frag->fr_literal, + value, fixP->fx_size); + else + /* Initialise the part of an instruction frag covered by the + relocation. (Many occurrences of frag_more followed by fix_new + lack any init of the frag.) Since VAX uses RELA relocs the + value we write into this field doesn't really matter. */ + memset (fixP->fx_where + fixP->fx_frag->fr_literal, 0, fixP->fx_size); } /* Convert a number from VAX byte order (little endian) @@ -2336,7 +2342,7 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp) if (fixp->fx_tcbit) abort (); - if (fixp->fx_r_type != BFD_RELOC_NONE) + if (fixp->fx_r_type != NO_RELOC) { code = fixp->fx_r_type; @@ -3379,7 +3385,7 @@ vax_cons (expressionS *exp, int size) case 2: return BFD_RELOC_16_PCREL; case 4: return BFD_RELOC_32_PCREL; } - return BFD_RELOC_NONE; + return NO_RELOC; } /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a @@ -3389,7 +3395,7 @@ void vax_cons_fix_new (fragS *frag, int where, unsigned int nbytes, expressionS *exp, bfd_reloc_code_real_type r) { - if (r == BFD_RELOC_NONE) + if (r == NO_RELOC) r = (nbytes == 1 ? BFD_RELOC_8 : nbytes == 2 ? BFD_RELOC_16 : BFD_RELOC_32); diff --git a/gas/testsuite/ChangeLog b/gas/testsuite/ChangeLog index 7a42746..efc129b 100644 --- a/gas/testsuite/ChangeLog +++ b/gas/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2014-06-16 Alan Modra + * gas/vax/elf-rel.d: Update. + +2014-06-16 Alan Modra + * gas/cris/rd-bkw4v32.d: Update. 2014-06-10 H.J. Lu diff --git a/gas/testsuite/gas/vax/elf-rel.d b/gas/testsuite/gas/vax/elf-rel.d index 7e2df40..d4b26c6 100644 --- a/gas/testsuite/gas/vax/elf-rel.d +++ b/gas/testsuite/gas/vax/elf-rel.d @@ -33,10 +33,10 @@ OFFSET [ ]+ TYPE VALUE Contents of section \.text: - 0000 0000fb00 affafb00 cff5fffb 00efeeff .* - 0010 fffffb00 ef000000 00d5afe4 d5cfe0ff .* - 0020 d5efdaff ffffd5ef 00000000 d5afd9d5 .* - 0030 cfddffd5 efe7ffff ffd5ef00 00000004 .* + 0000 0000fb00 af00fb00 cf0000fb 00ef0000 .* + 0010 0000fb00 ef000000 00d5af00 d5cf0000 .* + 0020 d5ef0000 0000d5ef 00000000 d5af00d5 .* + 0030 cf0000d5 ef000000 00d5ef00 00000004 .* Contents of section \.data: 0000 00000000 00000000 00000000 0000 .* #pass -- 2.7.4