This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[patch] Use symbolic constants instead of magic numbers.
- From: ppluzhnikov at google dot com (Paul Pluzhnikov)
- To: binutils at sourceware dot org
- Cc: ppluzhnikov at google dot com, cgd at google dot com
- Date: Fri, 11 Sep 2009 11:20:43 -0700 (PDT)
- Subject: [patch] Use symbolic constants instead of magic numbers.
Greetings,
Yesterday I was looking at (apparently undocumented) use of 0x8000 in ELF
version definitions, and reading readelf.c proved not very helpful.
Later Chris Demetriou pointed me to binutils/include/elf/common.h, which
is much more helpful.
Attached patch is rather on the obvious side, makes readelf.c use symbolic
constants instead of hard-coded "magic" numbers.
Thanks,
--
Paul Pluzhnikov
2009-09-11 Paul Pluzhnikov <ppluzhnikov@google.com>
* readelf.c (process_version_sections, process_symbol_table):
Use symbolic constants.
Index: readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.458
diff -u -p -u -r1.458 readelf.c
--- readelf.c 10 Sep 2009 13:40:44 -0000 1.458
+++ readelf.c 11 Sep 2009 18:13:48 -0000
@@ -6852,8 +6852,8 @@ process_version_sections (FILE * file)
break;
default:
- nn = printf ("%4x%c", data[cnt + j] & 0x7fff,
- data[cnt + j] & 0x8000 ? 'h' : ' ');
+ nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION,
+ data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' ');
check_def = 1;
check_need = 1;
@@ -6947,10 +6947,10 @@ process_version_sections (FILE * file)
offset += ivd.vd_next;
}
- while (ivd.vd_ndx != (data[cnt + j] & 0x7fff)
+ while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION)
&& ivd.vd_next != 0);
- if (ivd.vd_ndx == (data[cnt + j] & 0x7fff))
+ if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION))
{
Elf_External_Verdaux evda;
Elf_Internal_Verdaux ivda;
@@ -7564,7 +7564,7 @@ process_symbol_table (FILE * file)
check_def = (psym->st_shndx != SHN_UNDEF);
- if ((vers_data & 0x8000) || vers_data > 1)
+ if ((vers_data & VERSYM_HIDDEN) || vers_data > 1)
{
if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]
&& (is_nobits || ! check_def))
@@ -7656,7 +7656,7 @@ process_symbol_table (FILE * file)
offset += ivd.vd_next;
}
- while (ivd.vd_ndx != (vers_data & 0x7fff)
+ while (ivd.vd_ndx != (vers_data & VERSYM_VERSION)
&& ivd.vd_next != 0);
offset -= ivd.vd_next;
@@ -7668,7 +7668,7 @@ process_symbol_table (FILE * file)
ivda.vda_name = BYTE_GET (evda.vda_name);
if (psym->st_name != ivda.vda_name)
- printf ((vers_data & 0x8000)
+ printf ((vers_data & VERSYM_HIDDEN)
? "@%s" : "@@%s",
ivda.vda_name < strtab_size
? strtab + ivda.vda_name : "<corrupt>");