Extension: read inlining info in an NVIDIA extended line map

2021-09-05 Thread John Mellor-Crummey via Elfutils-devel
As of CUDA 11.2, NVIDIA added extensions to the line map section
of CUDA binaries to represent inlined functions. These extensions
include

 - two new fields in a line table row to represent inline 
   information: context, and functionname,

 - two new DWARF extended opcodes: DW_LNE_inlined_call, 
   DW_LNE_set_function_name,

 - an additional word in the line table header that indicates 
   the offset in the .debug_str function where the function 
   names for this line table begin, and

 - two new functions in the libdw API: dwarf_linecontext and 
   dwarf_linefunctionname, which return the new line table fields.

A line table row for an inlined function contains a non-zero
"context" value. The “context” field indicates the index of the
line table row that serves as the call site for an inlined
context.

The "functionname" field in a line table row is only meaningful
if the "context" field of the row is non-zero. A meaningful
"functionname" field contains an index into the .debug_str
section relative to the base offset established in the line table
header; the position in the .debug_str section indicates the name
of the inlined function.

These extensions resemble the proposed DWARF extensions
(http://dwarfstd.org/ShowIssue.php?issue=140906.1) by Cary
Coutant, but are not identical.

This patch adds integrates support for handling NVIDIA's extended
line maps into elfutil's libdw library and the readelf command
line utility.

Since this support is a non-standard extension to DWARF, all code
that implements the extensions is implemented between markers  
/* Begin NVIDIA_LINEMAP_INLINING_EXTENSIONS */ and 
/* End NVIDIA_LINEMAP_INLINING_EXTENSIONS */.

The definition below

 #define NVIDIA_LINEMAP_INLINING_EXTENSIONS 1

is added to elfutils/version.h, which enables a client of elfutils 
to test whether the NVIDIA line map extensions are present. 

Note: The support for NVIDIA extended line maps adds two integer
fields (context and functionname) to struct Dwarf_Line_s, which
makes the structure about 30% larger.

The patch includes a binary testfile_nvidia_linemap.bz2 that
contains an NVIDIA extended linemap along with two tests that
read the line map.

 - A test script run-nvidia-extended-linemap-readelf.sh 
   checks the output of readelf on the new test binary to 
   validate its dump of the line op codes containing context 
   and functionname entries.

 - A test program tests/nvidia_extended_linemap_libdw.c reads 
   the extended line map with dwarf_next_lines and dumps the 
   context and functionname fields of the line map where they 
   are relevant, i.e. the value of context is non-zero. A test 
   script run-nvidia-extended-linemap-libdw.sh runs this test 
   and validates its output.

A patch with the new functionality described above is attached.
--
John Mellor-Crummey Professor
Dept of Computer ScienceRice University
email: joh...@rice.edu  phone: 713-348-5179



0001-Read-inlining-info-in-NVIDIA-extended-line-map.patch
Description: Binary data





[PATCH] src: add -Wno-error=stack-usage= to AM_LDFLAGS

2021-09-05 Thread Dmitry V. Levin
While -Wstack-usage= is already excluded from AM_CFLAGS for various
tools in src using *_no_Wstack_usage variables, this obviously does not
help when LTO is enabled, so add -Wno-error=stack-usage= to AM_LDFLAGS
for linking tools in src.

References: https://sourceware.org/bugzilla/show_bug.cgi?id=24498
Signed-off-by: Dmitry V. Levin 
---
 config/ChangeLog | 4 
 config/eu.am | 2 ++
 src/ChangeLog| 4 
 src/Makefile.am  | 2 +-
 4 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/config/ChangeLog b/config/ChangeLog
index 70a1e923..b2c0af8a 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,7 @@
+2021-09-05  Dmitry V. Levin  
+
+   * eu.am (STACK_USAGE_NO_ERROR): New variable.
+
 2021-07-06  Alice Zhang  
 
 * debuginfod.sysconfig: Introduce default retry limit.
diff --git a/config/eu.am b/config/eu.am
index 2c3e4571..58cd3c4f 100644
--- a/config/eu.am
+++ b/config/eu.am
@@ -39,8 +39,10 @@ ARFLAGS = cr
 # Warn about stack usage of more than 256K = 262144 bytes.
 if ADD_STACK_USAGE_WARNING
 STACK_USAGE_WARNING=-Wstack-usage=262144
+STACK_USAGE_NO_ERROR=-Wno-error=stack-usage=
 else
 STACK_USAGE_WARNING=
+STACK_USAGE_NO_ERROR=
 endif
 
 if SANE_LOGICAL_OP_WARNING
diff --git a/src/ChangeLog b/src/ChangeLog
index b729eaa4..e83e0a5e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2021-09-05  Dmitry V. Levin  
+
+   * Makefile.am (AM_LDFLAGS): Add $(STACK_USAGE_NO_ERROR).
+
 2021-08-20  Saleem Abdulrasool  
 
* elfclassify.c: Remove error.h include.
diff --git a/src/Makefile.am b/src/Makefile.am
index 88d0ac8f..86d5bcf8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -23,7 +23,7 @@ AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libebl \
-I$(srcdir)/../libdw -I$(srcdir)/../libdwelf \
-I$(srcdir)/../libdwfl -I$(srcdir)/../libasm
 
-AM_LDFLAGS = -Wl,-rpath-link,../libelf:../libdw
+AM_LDFLAGS = -Wl,-rpath-link,../libelf:../libdw $(STACK_USAGE_NO_ERROR)
 
 bin_PROGRAMS = readelf nm size strip elflint findtextrel addr2line \
   elfcmp objdump ranlib strings ar unstrip stack elfcompress \
-- 
ldv