* dw2gencfi.c DWARF2_FDE_RELOC_SIZE
@ 2017-03-06 10:33 Alan Modra
2017-03-06 10:59 ` Jan Beulich
0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2017-03-06 10:33 UTC (permalink / raw)
To: binutils
Add asserts that reloc size matches encoding size, and tidy places
that use DWARF2_FDE_RELOC_SIZE or a hard-coded constant.
* dw2gencfi.c (encoding_size): Return unsigned int.
(emit_expr_encoded): Assert size matches reloc bitsize.
(output_fde): Use unsigned for offset_size and addr_size. Set
addr_size earlier and use in place of constant 4 and uses of
DWARF2_FDE_RELOC_SIZE. Assert it matches reloc bitsize.
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 24871a2..9b1849d 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,5 +1,13 @@
2017-03-06 Alan Modra <amodra@gmail.com>
+ * dw2gencfi.c (encoding_size): Return unsigned int.
+ (emit_expr_encoded): Assert size matches reloc bitsize.
+ (output_fde): Use unsigned for offset_size and addr_size. Set
+ addr_size earlier and use in place of constant 4 and uses of
+ DWARF2_FDE_RELOC_SIZE. Assert it matches reloc bitsize.
+
+2017-03-06 Alan Modra <amodra@gmail.com>
+
* dw2gencfi.c: Wrap overlong lines. Add parens for emacs
auto reformat. Formatting and whitespace fixes.
diff --git a/gas/dw2gencfi.c b/gas/dw2gencfi.c
index b90b48f..359e732 100644
--- a/gas/dw2gencfi.c
+++ b/gas/dw2gencfi.c
@@ -157,7 +157,7 @@ out_sleb128 (offsetT value)
output_leb128 (frag_more (sizeof_leb128 (value, 1)), value, 1);
}
-static offsetT
+static unsigned int
encoding_size (unsigned char encoding)
{
if (encoding == DW_EH_PE_omit)
@@ -183,7 +183,7 @@ encoding_size (unsigned char encoding)
static void
emit_expr_encoded (expressionS *exp, int encoding, bfd_boolean emit_encoding)
{
- offsetT size = encoding_size (encoding);
+ unsigned int size = encoding_size (encoding);
bfd_reloc_code_real_type code;
if (encoding == DW_EH_PE_omit)
@@ -197,6 +197,7 @@ emit_expr_encoded (expressionS *exp, int encoding, bfd_boolean emit_encoding)
{
reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, code);
char *p = frag_more (size);
+ gas_assert (size == howto->bitsize / 8);
md_number_to_chars (p, 0, size);
fix_new (frag_now, p - frag_now->fr_literal, size, exp->X_add_symbol,
exp->X_add_number, howto->pc_relative, code);
@@ -1934,8 +1935,8 @@ output_fde (struct fde_entry *fde, struct cie_entry *cie,
expressionS exp;
offsetT augmentation_size;
enum dwarf2_format fmt = DWARF2_FORMAT (now_seg);
- int offset_size;
- int addr_size;
+ unsigned int offset_size;
+ unsigned int addr_size;
after_size_address = symbol_temp_make ();
end_address = symbol_temp_make ();
@@ -1973,13 +1974,15 @@ output_fde (struct fde_entry *fde, struct cie_entry *cie,
{
bfd_reloc_code_real_type code
= tc_cfi_reloc_for_encoding (cie->fde_encoding);
+ addr_size = DWARF2_FDE_RELOC_SIZE;
if (code != BFD_RELOC_NONE)
{
reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, code);
- char *p = frag_more (4);
- md_number_to_chars (p, 0, 4);
- fix_new (frag_now, p - frag_now->fr_literal, 4, fde->start_address,
- 0, howto->pc_relative, code);
+ char *p = frag_more (addr_size);
+ gas_assert (addr_size == howto->bitsize / 8);
+ md_number_to_chars (p, 0, addr_size);
+ fix_new (frag_now, p - frag_now->fr_literal, addr_size,
+ fde->start_address, 0, howto->pc_relative, code);
}
else
{
@@ -1988,19 +1991,18 @@ output_fde (struct fde_entry *fde, struct cie_entry *cie,
#if CFI_DIFF_EXPR_OK
exp.X_add_symbol = fde->start_address;
exp.X_op_symbol = symbol_temp_new_now ();
- emit_expr (&exp, DWARF2_FDE_RELOC_SIZE); /* Code offset. */
+ emit_expr (&exp, addr_size); /* Code offset. */
#else
exp.X_op = O_symbol;
exp.X_add_symbol = fde->start_address;
#if defined(tc_cfi_emit_pcrel_expr)
- tc_cfi_emit_pcrel_expr (&exp, DWARF2_FDE_RELOC_SIZE); /* Code offset. */
+ tc_cfi_emit_pcrel_expr (&exp, addr_size); /* Code offset. */
#else
- emit_expr (&exp, DWARF2_FDE_RELOC_SIZE); /* Code offset. */
+ emit_expr (&exp, addr_size); /* Code offset. */
#endif
#endif
}
- addr_size = DWARF2_FDE_RELOC_SIZE;
}
else
{
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: dw2gencfi.c DWARF2_FDE_RELOC_SIZE
2017-03-06 10:33 dw2gencfi.c DWARF2_FDE_RELOC_SIZE Alan Modra
@ 2017-03-06 10:59 ` Jan Beulich
2017-03-06 11:45 ` Alan Modra
0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2017-03-06 10:59 UTC (permalink / raw)
To: Alan Modra; +Cc: binutils
>>> On 06.03.17 at 11:33, <amodra@gmail.com> wrote:
> @@ -1973,13 +1974,15 @@ output_fde (struct fde_entry *fde, struct cie_entry *cie,
> {
> bfd_reloc_code_real_type code
> = tc_cfi_reloc_for_encoding (cie->fde_encoding);
> + addr_size = DWARF2_FDE_RELOC_SIZE;
> if (code != BFD_RELOC_NONE)
> {
> reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, code);
> - char *p = frag_more (4);
> - md_number_to_chars (p, 0, 4);
> - fix_new (frag_now, p - frag_now->fr_literal, 4, fde->start_address,
> - 0, howto->pc_relative, code);
> + char *p = frag_more (addr_size);
> + gas_assert (addr_size == howto->bitsize / 8);
> + md_number_to_chars (p, 0, addr_size);
> + fix_new (frag_now, p - frag_now->fr_literal, addr_size,
> + fde->start_address, 0, howto->pc_relative, code);
> }
So I see you nevertheless decided to clean this up. However, is this
a good approach? What if a target wants/needs to use different
relocations for different encodings (which then may also be different
size)? I would have thought that addr_size needs to be derived from
the returned reloc type.
Jan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: dw2gencfi.c DWARF2_FDE_RELOC_SIZE
2017-03-06 10:59 ` Jan Beulich
@ 2017-03-06 11:45 ` Alan Modra
0 siblings, 0 replies; 3+ messages in thread
From: Alan Modra @ 2017-03-06 11:45 UTC (permalink / raw)
To: Jan Beulich; +Cc: binutils
On Mon, Mar 06, 2017 at 03:59:10AM -0700, Jan Beulich wrote:
> >>> On 06.03.17 at 11:33, <amodra@gmail.com> wrote:
> > @@ -1973,13 +1974,15 @@ output_fde (struct fde_entry *fde, struct cie_entry *cie,
> > {
> > bfd_reloc_code_real_type code
> > = tc_cfi_reloc_for_encoding (cie->fde_encoding);
> > + addr_size = DWARF2_FDE_RELOC_SIZE;
> > if (code != BFD_RELOC_NONE)
> > {
> > reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, code);
> > - char *p = frag_more (4);
> > - md_number_to_chars (p, 0, 4);
> > - fix_new (frag_now, p - frag_now->fr_literal, 4, fde->start_address,
> > - 0, howto->pc_relative, code);
> > + char *p = frag_more (addr_size);
> > + gas_assert (addr_size == howto->bitsize / 8);
> > + md_number_to_chars (p, 0, addr_size);
> > + fix_new (frag_now, p - frag_now->fr_literal, addr_size,
> > + fde->start_address, 0, howto->pc_relative, code);
> > }
>
> So I see you nevertheless decided to clean this up. However, is this
> a good approach? What if a target wants/needs to use different
> relocations for different encodings (which then may also be different
> size)? I would have thought that addr_size needs to be derived from
> the returned reloc type.
It would make even more sense to use
addr_size = encoding_size (cie->fde_encoding);
deriving both reloc and size from the encoding.
I thought about doing that but got tired of running the testsuite.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-03-06 11:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-06 10:33 dw2gencfi.c DWARF2_FDE_RELOC_SIZE Alan Modra
2017-03-06 10:59 ` Jan Beulich
2017-03-06 11:45 ` Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).