View Issue Details

IDProjectCategoryView StatusLast Update
0000591filegeneralpublic2017-02-01 12:42
ReporterJason Vas Dias 
Assigned ToChristos Zoulas 
PrioritynormalSeverityfeatureReproducibilityN/A
Status resolvedResolutionfixed 
Product Version5.29 
Target VersionFixed in Version5.30 
Summary0000591: new feature request : please make file report for ELF files whether the .debug_info section is actually present, or not
DescriptionI have applied this patch to the src/readelf.c of a git checkout of the FILE-29 branch,
which, after file(1) emits the string 'stripped' or 'not stripped' for an ELF file,
will cause it also emit 'with .debug-info' if and only if the '.debug_info' section actually existed in the ELF file :
<quote><code>

 diff -up src/readelf.c.5-29 src/readelf.c
--- src/readelf.c.5-29	2017-01-29 15:58:31.063608266 +0000
+++ src/readelf.c	2017-01-29 14:06:56.501660625 +0000
@@ -1193,7 +1193,8 @@ doshn(struct magic_set *ms, int clazz, i
     uint64_t cap_sf1 = 0;	/* SunOS 5.x software capabilites */
     char name[50];
     ssize_t namesize;
-
+        unsigned char has_debug_info = 0;
+
     if (size != xsh_sizeof) {
         if (file_printf(ms, ", corrupted section header size") == -1)
             return -1;
@@ -1216,8 +1217,11 @@ doshn(struct magic_set *ms, int clazz, i
         }
         name[namesize] = '\0';
         if (strcmp(name, ".debug_info") == 0)
-			stripped = 0;
-
+                {
+		    stripped = 0;
+                    has_debug_info = 1;
+                }
+
         if (pread(fd, xsh_addr, xsh_sizeof, off) < (ssize_t)xsh_sizeof) {
             file_badread(ms);
             return -1;
@@ -1372,6 +1376,11 @@ doshn(struct magic_set *ms, int clazz, i

     if (file_printf(ms, ", %sstripped", stripped ? "" : "not ") == -1)
         return -1;
+
+	if (has_debug_info)
+          if(file_printf(ms, ", with debug_info") == -1)
+		return -1;
+
     if (cap_hw1) {
         const cap_desc_t *cdp;
         switch (mach) {
</code></quote>

So, for example, on my system, /usr/bin/bash is a binary which has been split into a separate debug info file,
and had debug info sections ONLY excised, with:
  $ objcopy --only-keep-debug bash bash-${BUILD_ID}.debuginfo
  $ strip --keep-file-symbols bash
So file(1) before the patch would report :
  $ file /bin/bash
/bin/bash: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=a1d65eecc782bbce413088b256fb3c83e7344ea5, not stripped
So there was no way of determining if it had a .debug_info section or not, except by doing something like:
  $ readelf -S /bin/bash | grep \.debug_info
But file(1) already knows this information, in determining if the file is stripped or not .
So please could it print it out; it greatly simplifies scripts that want to know if a file contains .debug_info or not .
Perhaps it could be optionally enabled with a new option or $FILE_EMIT_WITH_DEBUGINFO environment variable setting.
TagsNo tags attached.

Relationships

Activities

Jason Vas Dias

Jason Vas Dias

2017-01-29 16:11

reporter  

readelf.c.patch (1,176 bytes)
diff -up src/readelf.c.5-29 src/readelf.c
--- src/readelf.c.5-29	2017-01-29 15:58:31.063608266 +0000
+++ src/readelf.c	2017-01-29 14:06:56.501660625 +0000
@@ -1193,7 +1193,8 @@ doshn(struct magic_set *ms, int clazz, i
 	uint64_t cap_sf1 = 0;	/* SunOS 5.x software capabilites */
 	char name[50];
 	ssize_t namesize;
-
+        unsigned char has_debug_info = 0;
+        
 	if (size != xsh_sizeof) {
 		if (file_printf(ms, ", corrupted section header size") == -1)
 			return -1;
@@ -1216,8 +1217,11 @@ doshn(struct magic_set *ms, int clazz, i
 		}
 		name[namesize] = '\0';
 		if (strcmp(name, ".debug_info") == 0)
-			stripped = 0;
-
+                {
+		    stripped = 0;
+                    has_debug_info = 1;
+                }
+                
 		if (pread(fd, xsh_addr, xsh_sizeof, off) < (ssize_t)xsh_sizeof) {
 			file_badread(ms);
 			return -1;
@@ -1372,6 +1376,11 @@ doshn(struct magic_set *ms, int clazz, i
 
 	if (file_printf(ms, ", %sstripped", stripped ? "" : "not ") == -1)
 		return -1;
+
+	if (has_debug_info)
+          if(file_printf(ms, ", with debug_info") == -1)
+		return -1;
+        
 	if (cap_hw1) {
 		const cap_desc_t *cdp;
 		switch (mach) {
readelf.c.patch (1,176 bytes)
Jason Vas Dias

Jason Vas Dias

2017-01-30 01:52

reporter  

log.sh (2,067 bytes)
elf_file.sh (8,687 bytes)
Jason Vas Dias

Jason Vas Dias

2017-01-30 01:55

reporter   ~0001471

Demonstrates use for 'with debug_info' string :
$ (. ./elf_file.sh ; elf_file /bin/bash)
declare -A elf='([interpreter]="/lib64/ld-linux-x86-64.so.2" [build_id]="a1d65eecc782bbce413088b256fb3c83e7344ea5" [os]="GNU/Linux 2.6.32" [link]="dynamic" [file]="/bin/bash" [bits]="64" [stripped]="not stripped" [abi]="version 1 (SYSV)" [byte_order]="LSB" [type]="executable" [arch]="x86-64" )'
Christos Zoulas

Christos Zoulas

2017-02-01 12:42

manager   ~0001474

Fixed, thanks!

Issue History

Date Modified Username Field Change
2017-01-29 16:11 Jason Vas Dias New Issue
2017-01-29 16:11 Jason Vas Dias File Added: readelf.c.patch
2017-01-30 01:52 Jason Vas Dias File Added: elf_file.sh
2017-01-30 01:52 Jason Vas Dias File Added: log.sh
2017-01-30 01:55 Jason Vas Dias Note Added: 0001471
2017-02-01 12:42 Christos Zoulas Assigned To => Christos Zoulas
2017-02-01 12:42 Christos Zoulas Status new => assigned
2017-02-01 12:42 Christos Zoulas Assigned To Christos Zoulas =>
2017-02-01 12:42 Christos Zoulas Assigned To => Christos Zoulas
2017-02-01 12:42 Christos Zoulas Status assigned => resolved
2017-02-01 12:42 Christos Zoulas Resolution open => fixed
2017-02-01 12:42 Christos Zoulas Fixed in Version => 5.30
2017-02-01 12:42 Christos Zoulas Note Added: 0001474