summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Zeter <[email protected]>2025-04-03 17:24:13 +1000
committerMark Wielaard <[email protected]>2025-04-04 13:57:50 +0200
commitef1ca49f5289ba8836a5f98b6ee8e387b96ebaf3 (patch)
treefd03fd57806cfe960b6e0e49bdbfa3259c7ecde0
parent1159fec63f438a47a597e0608c47dc5ab850246d (diff)
readelf: Add 'Key to Flags' to eu-readelf --section-headers output
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 <[email protected]>
-rw-r--r--src/readelf.c11
-rwxr-xr-xtests/run-copyadd-sections.sh4
-rwxr-xr-xtests/run-large-elf-file.sh2
-rwxr-xr-xtests/run-readelf-z.sh32
-rwxr-xr-xtests/run-retain.sh4
-rwxr-xr-xtests/run-strip-remove-keep.sh64
-rwxr-xr-xtests/test-copymany-subr.sh2
7 files changed, 115 insertions, 4 deletions
diff --git a/src/readelf.c b/src/readelf.c
index e5bc16a5..5b0e7b47 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -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
diff --git a/tests/run-copyadd-sections.sh b/tests/run-copyadd-sections.sh
index bc20f6ee..f8304926 100755
--- a/tests/run-copyadd-sections.sh
+++ b/tests/run-copyadd-sections.sh
@@ -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}
diff --git a/tests/run-large-elf-file.sh b/tests/run-large-elf-file.sh
index 8108cb4b..249ecd99 100755
--- a/tests/run-large-elf-file.sh
+++ b/tests/run-large-elf-file.sh
@@ -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}
diff --git a/tests/run-readelf-z.sh b/tests/run-readelf-z.sh
index 6dbd2f14..859d801e 100755
--- a/tests/run-readelf-z.sh
+++ b/tests/run-readelf-z.sh
@@ -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
diff --git a/tests/run-retain.sh b/tests/run-retain.sh
index c5376de4..ac39a65b 100755
--- a/tests/run-retain.sh
+++ b/tests/run-retain.sh
@@ -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
diff --git a/tests/run-strip-remove-keep.sh b/tests/run-strip-remove-keep.sh
index 92647fa7..c2bd63f4 100755
--- a/tests/run-strip-remove-keep.sh
+++ b/tests/run-strip-remove-keep.sh
@@ -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
diff --git a/tests/test-copymany-subr.sh b/tests/test-copymany-subr.sh
index 054103b4..ed39a69b 100755
--- a/tests/test-copymany-subr.sh
+++ b/tests/test-copymany-subr.sh
@@ -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