public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: Nick Clifton <nickc@redhat.com>
Cc: Tom Tromey <tom@tromey.com>,
	Nick Clifton via Binutils <binutils@sourceware.org>
Subject: gas: Use udata for DW_AT_high_pc when emitting DWARF4 (Was: Broken GAS DWARF tests)
Date: Mon, 3 Aug 2020 22:11:27 +0200	[thread overview]
Message-ID: <20200803201127.GB2718@wildebeest.org> (raw)
In-Reply-To: <20200803131109.GA2718@wildebeest.org>

[-- Attachment #1: Type: text/plain, Size: 784 bytes --]

On Mon, Aug 03, 2020 at 03:11:09PM +0200, Mark Wielaard wrote:
> On Thu, Jul 30, 2020 at 04:21:17PM +0100, Nick Clifton via Binutils wrote:
> > Plus, and this is very minor, version 4 DWARF line number tables are 
> > actually bigger than version 3 tables, because of the addition of the
> > Maximum Ops Per Instruction field in the table header.
> 
> This is most likely compensated by the fact that for DWARF4 we loose a
> relocation in the CU DIE header for DW_AT_high_pc. We could save a few
> bytes if we would be able to express the difference between low_pc and
> high_pc as uleb128 (maybe we can simply use emit_leb128_expr?).

This seems to work as intended and is indeed a lot shorter (before
this patch we always used either data4 (32bits) or data8 (64bits).

Cheers,

Mark

[-- Attachment #2: 0001-gas-Use-udata-for-DW_AT_high_pc-when-emitting-DWARF4.patch --]
[-- Type: text/x-diff, Size: 3145 bytes --]

From 0b202965ae7aa2ed2ce3d3db29d806ce0f1da0d4 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Mon, 3 Aug 2020 22:02:24 +0200
Subject: [PATCH] gas: Use udata for DW_AT_high_pc when emitting DWARF4

For DWARF4 DW_AT_high_pc can be expressed as constant offset from
DW_AT_low_pc which saves a relocation. Use DW_FORM_udate (uleb128)
to keep the constant value as small as possible.

gas/ChangeLog:

       * dwarf2dbg.c (out_debug_abbrev): When DWARF2_VERSION >= 4, use
       DW_FORM_udata for DW_AT_high_pc.
       (out_debug_info): Use emit_leb128_expr for DW_AT_high_pc, when
       DWARF2_VERSION >= 4.
       * read.c (emit_leb128_exp): No longer static.
       * read.h (emit_leb128_exp): Define.
---
 gas/ChangeLog   | 9 +++++++++
 gas/dwarf2dbg.c | 8 +++++---
 gas/read.c      | 2 +-
 gas/read.h      | 1 +
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 8dee8190b0..ff2f762ed7 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,12 @@
+2020-08-04  Mark Wielaard  <mark@klomp.org>
+
+	* dwarf2dbg.c (out_debug_abbrev): When DWARF2_VERSION >= 4, use
+	DW_FORM_udata for DW_AT_high_pc.
+	(out_debug_info): Use emit_leb128_expr for DW_AT_high_pc, when
+	DWARF2_VERSION >= 4.
+	* read.c (emit_leb128_exp): No longer static.
+	* read.h (emit_leb128_exp): Define.
+
 2020-07-30  H.J. Lu  <hongjiu.lu@intel.com>
 
 	PR gas/26305
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 69955fea5b..64333aa1a5 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -2427,8 +2427,7 @@ out_debug_abbrev (segT abbrev_seg,
       if (DWARF2_VERSION < 4)
 	out_abbrev (DW_AT_high_pc, DW_FORM_addr);
       else
-	out_abbrev (DW_AT_high_pc, (sizeof_address == 4
-				    ? DW_FORM_data4 : DW_FORM_data8));
+	out_abbrev (DW_AT_high_pc, DW_FORM_udata);
     }
   else
     {
@@ -2497,7 +2496,10 @@ out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT ranges_seg,
 	}
       exp.X_add_symbol = all_segs->text_end;
       exp.X_add_number = 0;
-      emit_expr (&exp, sizeof_address);
+      if (DWARF2_VERSION < 4)
+	emit_expr (&exp, sizeof_address);
+      else
+	emit_leb128_expr (&exp, 0);
     }
   else
     {
diff --git a/gas/read.c b/gas/read.c
index 8f93c2ba2b..f192cc16d5 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -5138,7 +5138,7 @@ output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, unsigned int size, int sign)
 /* Generate the appropriate fragments for a given expression to emit a
    leb128 value.  SIGN is 1 for sleb, 0 for uleb.  */
 
-static void
+void
 emit_leb128_expr (expressionS *exp, int sign)
 {
   operatorT op = exp->X_op;
diff --git a/gas/read.h b/gas/read.h
index 502f3b6f2d..ffcdbb69a7 100644
--- a/gas/read.h
+++ b/gas/read.h
@@ -132,6 +132,7 @@ extern void emit_expr_with_reloc (expressionS *exp, unsigned int nbytes,
 				  TC_PARSE_CONS_RETURN_TYPE);
 extern void emit_expr_fix (expressionS *, unsigned int, fragS *, char *,
 			   TC_PARSE_CONS_RETURN_TYPE);
+extern void emit_leb128_expr (expressionS *, int);
 extern void equals (char *, int);
 extern void float_cons (int);
 extern void ignore_rest_of_line (void);
-- 
2.20.1


  reply	other threads:[~2020-08-03 20:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-30  9:45 Broken GAS DWARF tests Nick Clifton
2020-07-30 11:13 ` H.J. Lu
2020-07-30 11:53   ` H.J. Lu
2020-07-30 14:02 ` Nick Clifton
2020-07-30 14:12   ` Andreas Schwab
2020-07-30 14:44   ` Tom Tromey
2020-07-30 15:21     ` Nick Clifton
2020-08-03 13:11       ` Mark Wielaard
2020-08-03 20:11         ` Mark Wielaard [this message]
2020-08-04  3:53           ` gas: Use udata for DW_AT_high_pc when emitting DWARF4 (Was: Broken GAS DWARF tests) Alan Modra
2020-08-06  6:09             ` Fangrui Song
2020-08-06 11:49               ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200803201127.GB2718@wildebeest.org \
    --to=mark@klomp.org \
    --cc=binutils@sourceware.org \
    --cc=nickc@redhat.com \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).