aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2018-06-08 10:28:38 -0700
committerH.J. Lu <hjl.tools@gmail.com>2018-06-08 10:28:52 -0700
commit67c0579669ba1fc265d770252fab31babf887329 (patch)
tree34059924ead164f11bc21fd73ccab758153bd9f7 /scripts
parent1c09524e4db3efd797ebcfcd8241bdb78f0b06f0 (diff)
downloadglibc-67c0579669ba1fc265d770252fab31babf887329.zip
glibc-67c0579669ba1fc265d770252fab31babf887329.tar.gz
glibc-67c0579669ba1fc265d770252fab31babf887329.tar.bz2
Mark _init and _fini as hidden [BZ #23145]
_init and _fini are special functions provided by glibc for linker to define DT_INIT and DT_FINI in executable and shared library. They should never be put in dynamic symbol table. This patch marks them as hidden to remove them from dynamic symbol table. Tested with build-many-glibcs.py. [BZ #23145] * elf/Makefile (tests-special): Add $(objpfx)check-initfini.out. ($(all-built-dso:=.dynsym): New target. (common-generated): Add $(all-built-dso:$(common-objpfx)%=%.dynsym). ($(objpfx)check-initfini.out): New target. (generated): Add check-initfini.out. * scripts/check-initfini.awk: New file. * sysdeps/aarch64/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/alpha/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/arm/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/hppa/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/i386/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/ia64/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/m68k/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/microblaze/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/mips/mips32/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/mips/mips64/n32/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/mips/mips64/n64/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/nios2/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/powerpc/powerpc32/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/powerpc/powerpc64/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/s390/s390-32/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/s390/s390-64/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/sh/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/sparc/crti.S (_init): Mark as hidden. (_fini): Likewise. * sysdeps/x86_64/crti.S (_init): Mark as hidden. (_fini): Likewise.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/check-initfini.awk63
1 files changed, 63 insertions, 0 deletions
diff --git a/scripts/check-initfini.awk b/scripts/check-initfini.awk
new file mode 100644
index 0000000..19514a9
--- /dev/null
+++ b/scripts/check-initfini.awk
@@ -0,0 +1,63 @@
+# Copyright (C) 2018 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
+
+# This awk script expects to get command-line files that are each
+# the output of 'readelf -W --dyn-syms' on a single shared object.
+# It exits successfully (0) if none contained _init nor _fini in dynamic
+# symbol table.
+# It fails (1) if any did contain _init or _fini in dynamic symbol table.
+# It fails (2) if the input did not take the expected form.
+
+BEGIN { result = _init = _fini = sanity = 0 }
+
+function check_one(name) {
+ if (!sanity) {
+ print name ": *** input did not look like readelf -d output";
+ result = 2;
+ } else {
+ ok = 1;
+ if (_init) {
+ print name ": *** _init is in dynamic symbol table";
+ result = result ? result : 1;
+ ok = 0;
+ }
+ if (_fini) {
+ print name ": *** _fini is in dynamic symbol table";
+ result = result ? result : 1;
+ ok = 0;
+ }
+ if (ok)
+ print name ": OK";
+ }
+
+ _init = _fini = sanity = 0
+}
+
+FILENAME != lastfile {
+ if (lastfile)
+ check_one(lastfile);
+ lastfile = FILENAME;
+}
+
+$1 == "Symbol" && $2 == "table" && $3 == "'.dynsym'" { sanity = 1 }
+$8 == "_init" { _init = 1 }
+$8 == "_fini" { _fini = 1 }
+
+END {
+ check_one(lastfile);
+ exit(result);
+}