]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Add 'Key to Flags' to eu-readelf --section-headers output
authorSamuel Zeter <samuelzeter@gmail.com>
Thu, 3 Apr 2025 07:24:13 +0000 (17:24 +1000)
committerMark Wielaard <mark@klomp.org>
Fri, 4 Apr 2025 11:57:50 +0000 (13:57 +0200)
When printing section headers, also include a key to what each flag
is at the end of the section header output.

   * src/readelf.c (print_flag_info): New function.
   (print_shdr): Call print_flag_info.
   * tests/run-copyadd-sections.sh: Fix .extra grep by escaping \.
   * tests/run-large-elf-file.sh: Likewise.
   * tests/test-copymany-subr.sh: Likewise.
   * tests/run-readelf-z.sh: Add Key to Flags to expected output.
   * tests/run-retain.sh: Likewise.
   * tests/run-strip-remove-keep.sh: Likewise.

https://sourceware.org/bugzilla/show_bug.cgi?id=29571

Signed-off-by: Samuel Zeter <samuelzeter@gmail.com>
src/readelf.c
tests/run-copyadd-sections.sh
tests/run-large-elf-file.sh
tests/run-readelf-z.sh
tests/run-retain.sh
tests/run-strip-remove-keep.sh
tests/test-copymany-subr.sh

index e5bc16a5bc4382d5cbe66cd28e809af4659ae886..5b0e7b474064466f0fb19f0b56903c3046503746 100644 (file)
@@ -341,6 +341,7 @@ static void print_strings (Ebl *ebl);
 static void dump_archive_index (Elf *, const char *);
 static void print_dwarf_addr (Dwfl_Module *dwflmod, int address_size,
                              Dwarf_Addr address, Dwarf_Addr raw);
+static void print_flag_info(void);
 
 enum dyn_idx
 {
@@ -1406,9 +1407,19 @@ There are %zd section headers, starting at offset %#" PRIx64 ":\n\
        }
     }
 
+  print_flag_info();
   fputc ('\n', stdout);
 }
 
+/* Print flag information.  */
+static void
+print_flag_info (void)
+{
+       puts ("Key to Flags:");
+       puts ("  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),");
+       puts ("  L (link order), N (extra OS processing required), G (group), T (TLS),");
+       puts ("  C (compressed), O (ordered), R (GNU retain), E (exclude)");
+}
 
 /* Print the program header.  */
 static void
index bc20f6eefb9c1a806bfaa1f8157c86f6354efb09..f8304926d9f5bdf8e5b856906e4945e9ea27cdbb 100755 (executable)
@@ -33,7 +33,7 @@ test_copy_and_add ()
   # Can we add a section (in-place)?
   testrun ${abs_builddir}/addsections 3 ${out_file}
   testrun ${abs_top_builddir}/src/readelf -S ${out_file} > readelf.out
-  nr=$(grep '.extra' readelf.out | wc -l)
+  nr=$(grep '\.extra' readelf.out | wc -l)
   if test ${nr} != 3; then
     # Show what went wrong
     testrun ${abs_top_builddir}/src/readelf -S ${out_file}
@@ -49,7 +49,7 @@ test_copy_and_add ()
   # because mremap cannot extend too much.
   testrun ${abs_builddir}/addsections --mmap 1 ${out_file_mmap}
   testrun ${abs_top_builddir}/src/readelf -S ${out_file_mmap} > readelf.out
-  nr=$(grep '.extra' readelf.out | wc -l)
+  nr=$(grep '\.extra' readelf.out | wc -l)
   if test ${nr} != 1; then
     # Show what went wrong
     testrun ${abs_top_builddir}/src/readelf -S ${out_file_mmap}
index 8108cb4be7b767b2c9c1719101ea8db7426050b2..249ecd99cbfb1d6bd620d6bc64a320fad83a6a66 100755 (executable)
@@ -84,7 +84,7 @@ test_file ()
   echo "addsections 2 ${in_file} 2147483648"
   testrun ${abs_builddir}/addsections 2 ${in_file} 2147483648
   testrun ${abs_top_builddir}/src/readelf -S ${in_file} > ${readelf_out}
-  nr=$(grep '.extra' ${readelf_out} | wc -l)
+  nr=$(grep '\.extra' ${readelf_out} | wc -l)
   if test ${nr} != 2; then
     # Show what went wrong
     cat ${readelf_out}
index 6dbd2f144bdfe9cb29e26d24b8b217cfb454d047..859d801e7a260a73c22704611ebc33348384dda7 100755 (executable)
@@ -38,6 +38,10 @@ Section Headers:
 [ 6] .shstrtab            STRTAB       0000000000000000 00000384 00000059  0        0   0  1
 [ 7] .symtab              SYMTAB       0000000000000000 000000a8 00000168 24        8   8  8
 [ 8] .strtab              STRTAB       0000000000000000 00000210 0000004b  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -61,6 +65,10 @@ Section Headers:
 [ 7] .shstrtab            STRTAB       0000000000000000 000003d0 00000063  0        0   0  1
 [ 8] .symtab              SYMTAB       0000000000000000 000000f0 00000180 24        9   9  8
 [ 9] .strtab              STRTAB       0000000000000000 00000270 00000044  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -83,6 +91,10 @@ Section Headers:
 [ 6] .shstrtab            STRTAB       0000000000000000 000003a8 00000056  0        0   0  1
 [ 7] .symtab              SYMTAB       0000000000000000 000000a8 00000168 24        8   8  8
 [ 8] .strtab              STRTAB       0000000000000000 00000210 0000004b  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -106,6 +118,10 @@ Section Headers:
 [ 7] .shstrtab            STRTAB       0000000000000000 000003f4 00000060  0        0   0  1
 [ 8] .symtab              SYMTAB       0000000000000000 000000f0 00000180 24        9   9  8
 [ 9] .strtab              STRTAB       0000000000000000 00000270 00000044  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -128,6 +144,10 @@ Section Headers:
 [ 6] .shstrtab            STRTAB       00000000 0002e2 000059  0        0   0  1
 [ 7] .symtab              SYMTAB       00000000 000080 0000f0 16        8   8  4
 [ 8] .strtab              STRTAB       00000000 000170 00004b  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -151,6 +171,10 @@ Section Headers:
 [ 7] .shstrtab            STRTAB       00000000 00032c 000063  0        0   0  1
 [ 8] .symtab              SYMTAB       00000000 0000c8 000110 16        9   9  4
 [ 9] .strtab              STRTAB       00000000 0001d8 000045  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -173,6 +197,10 @@ Section Headers:
 [ 6] .shstrtab            STRTAB       00000000 0002e2 000056  0        0   0  1
 [ 7] .symtab              SYMTAB       00000000 000080 0000f0 16        8   8  4
 [ 8] .strtab              STRTAB       00000000 000170 00004b  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -196,6 +224,10 @@ Section Headers:
 [ 7] .shstrtab            STRTAB       00000000 00032c 000060  0        0   0  1
 [ 8] .symtab              SYMTAB       00000000 0000c8 000110 16        9   9  4
 [ 9] .strtab              STRTAB       00000000 0001d8 000045  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
index c5376de4e6a01afd1d3cbb4af27c632780f18e5c..ac39a65b77abbb9ecdae85afbecd32ad00101e83 100755 (executable)
@@ -38,6 +38,10 @@ Section Headers:
 [ 6] .symtab              SYMTAB       0000000000000000 00000078 00000090 24        7   6  8
 [ 7] .strtab              STRTAB       0000000000000000 00000108 00000001  0        0   0  1
 [ 8] .shstrtab            STRTAB       0000000000000000 00000109 0000004c  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
index 92647fa7a54aa5e1c3e5ca74ec1a2925cb10c6aa..c2bd63f44131f0b13164c0eb9986cb02f1101c63 100755 (executable)
@@ -63,6 +63,10 @@ Section Headers:
 [24] .strtab              STRTAB       00000000 0007d8 000235  0        0   0  1
 [25] .gnu_debuglink       PROGBITS     00000000 000a10 000014  0        0   0  4
 [26] .shstrtab            STRTAB       00000000 000a24 0000d1  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 echo readelf testfile.debug
@@ -106,6 +110,10 @@ Section Headers:
 [32] .shstrtab            STRTAB       00000000 003d36 00012e  0        0   0  1
 [33] .symtab              SYMTAB       00000000 003e64 0005a0 16       34  68  4
 [34] .strtab              STRTAB       00000000 004404 000235  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -150,6 +158,10 @@ Section Headers:
 [25] .strtab              STRTAB       00000000 000ce8 000235  0        0   0  1
 [26] .gnu_debuglink       PROGBITS     00000000 000f20 000014  0        0   0  4
 [27] .shstrtab            STRTAB       00000000 000f34 0000d9  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 echo readelf testfile.debug
@@ -193,6 +205,10 @@ Section Headers:
 [32] .shstrtab            STRTAB       00000000 003d36 00012e  0        0   0  1
 [33] .symtab              NOBITS       00000000 003e64 0005a0 16       34  68  4
 [34] .strtab              NOBITS       00000000 003e64 000235  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -238,6 +254,10 @@ Section Headers:
 [24] .strtab              STRTAB       0000000000000000 0000085c 00000175  0        0   0  1
 [25] .gnu_debuglink       PROGBITS     0000000000000000 000009d4 00000014  0        0   0  4
 [26] .shstrtab            STRTAB       0000000000000000 000009e8 000000ee  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 echo readelf testfile.debug
@@ -273,6 +293,10 @@ Section Headers:
 [24] .shstrtab            STRTAB       0000000000000000 000001c0 000000e7  0        0   0  1
 [25] .symtab              SYMTAB       0000000000000000 000002a8 000004f8 24       26  44  8
 [26] .strtab              STRTAB       0000000000000000 000007a0 00000175  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -317,6 +341,10 @@ Section Headers:
 [24] .strtab              STRTAB       0000000000000000 00000d10 00000175  0        0   0  1
 [25] .gnu_debuglink       PROGBITS     0000000000000000 00000e88 00000014  0        0   0  4
 [26] .shstrtab            STRTAB       0000000000000000 00000e9c 000000ed  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 echo readelf testfile.debug
@@ -352,6 +380,10 @@ Section Headers:
 [24] .shstrtab            STRTAB       0000000000000000 000001ec 000000e7  0        0   0  1
 [25] .symtab              NOBITS       0000000000000000 000002d8 000004f8 24       26  44  8
 [26] .strtab              NOBITS       0000000000000000 000002d8 00000175  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -396,6 +428,10 @@ Section Headers:
 [25] .strtab              STRTAB       00000000 0007d8 000235  0        0   0  1
 [26] .gnu_debuglink       PROGBITS     00000000 000a10 000014  0        0   0  4
 [27] .shstrtab            STRTAB       00000000 000a24 0000d7  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 echo readelf testfile.debug
@@ -439,6 +475,10 @@ Section Headers:
 [32] .shstrtab            STRTAB       00000000 003d36 00012e  0        0   0  1
 [33] .symtab              SYMTAB       00000000 003e64 0005a0 16       34  68  4
 [34] .strtab              STRTAB       00000000 004404 000235  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -484,6 +524,10 @@ Section Headers:
 [26] .note                NOTE         00000000 00278c 0000a0  0        0   0  1
 [27] .gnu_debuglink       PROGBITS     00000000 00282c 000014  0        0   0  4
 [28] .shstrtab            STRTAB       00000000 002840 0000de  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 echo readelf testfile.debug
@@ -527,6 +571,10 @@ Section Headers:
 [32] .shstrtab            STRTAB       00000000 001ce2 00012e  0        0   0  1
 [33] .symtab              SYMTAB       00000000 001e10 0005a0 16       34  68  4
 [34] .strtab              STRTAB       00000000 0023b0 000235  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -570,6 +618,10 @@ Section Headers:
 [24] .strtab              STRTAB       0000000000000000 0000085c 00000175  0        0   0  1
 [25] .gnu_debuglink       PROGBITS     0000000000000000 000009d4 00000014  0        0   0  4
 [26] .shstrtab            STRTAB       0000000000000000 000009e8 000000ee  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 echo readelf testfile.debug
@@ -605,6 +657,10 @@ Section Headers:
 [24] .shstrtab            STRTAB       0000000000000000 000001c0 000000e7  0        0   0  1
 [25] .symtab              SYMTAB       0000000000000000 000002a8 000004f8 24       26  44  8
 [26] .strtab              STRTAB       0000000000000000 000007a0 00000175  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
@@ -647,6 +703,10 @@ Section Headers:
 [23] .comment             PROGBITS     0000000000000000 00000830 0000002c  1 MS     0   0  1
 [24] .gnu_debuglink       PROGBITS     0000000000000000 0000085c 00000014  0        0   0  4
 [25] .shstrtab            STRTAB       0000000000000000 00000870 000000e6  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 echo readelf testfile.debug
@@ -682,6 +742,10 @@ Section Headers:
 [24] .shstrtab            STRTAB       0000000000000000 000001c0 000000e7  0        0   0  1
 [25] .symtab              SYMTAB       0000000000000000 000002a8 000004f8 24       26  44  8
 [26] .strtab              STRTAB       0000000000000000 000007a0 00000175  0        0   0  1
+Key to Flags:
+  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+  L (link order), N (extra OS processing required), G (group), T (TLS),
+  C (compressed), O (ordered), R (GNU retain), E (exclude)
 
 EOF
 
index 054103b40b31b740ef8df407a2bff9183637b407..ed39a69bb05ff7e584154f68e0560e71c044d220 100755 (executable)
@@ -37,7 +37,7 @@ test_copy_and_add ()
   # Can we add a section (in-place)?
   testrun ${abs_builddir}/addsections 32768 ${out_file}
   testrun ${abs_top_builddir}/src/readelf -S ${out_file} > readelf.out
-  nr=$(grep '.extra' readelf.out | wc -l)
+  nr=$(grep '\.extra' readelf.out | wc -l)
   # We try twice...
   if test ${nr} != 32768 -a ${nr} != 65536; then
     # Show what went wrong