]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Mark _init and _fini as hidden [BZ #23145]
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 8 Jun 2018 17:28:38 +0000 (10:28 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 8 Jun 2018 17:28:52 +0000 (10:28 -0700)
_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.

22 files changed:
ChangeLog
elf/Makefile
scripts/check-initfini.awk [new file with mode: 0644]
sysdeps/aarch64/crti.S
sysdeps/alpha/crti.S
sysdeps/arm/crti.S
sysdeps/hppa/crti.S
sysdeps/i386/crti.S
sysdeps/ia64/crti.S
sysdeps/m68k/crti.S
sysdeps/microblaze/crti.S
sysdeps/mips/mips32/crti.S
sysdeps/mips/mips64/n32/crti.S
sysdeps/mips/mips64/n64/crti.S
sysdeps/nios2/crti.S
sysdeps/powerpc/powerpc32/crti.S
sysdeps/powerpc/powerpc64/crti.S
sysdeps/s390/s390-32/crti.S
sysdeps/s390/s390-64/crti.S
sysdeps/sh/crti.S
sysdeps/sparc/crti.S
sysdeps/x86_64/crti.S

index b1d694ad0cea9dfc70c82660859d0d433de8b11a..73b25958bc04b134db1e28ba3e32d51ae76e8a5d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,51 @@
+2018-06-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+       [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.
+
 2018-06-06  Tulio Magno Quites Machado Filho  <tuliom@linux.ibm.com>
 
        * sysdeps/powerpc/powerpc64/le/fpu/e_sqrtf128.c
index 2dcd2b88e0797ac7c0686653b34a9626847e94bd..f221422de3d5b7c83408435a6c539e511d3f3898 100644 (file)
@@ -348,7 +348,7 @@ ifeq ($(run-built-tests),yes)
 tests-special += $(objpfx)tst-pathopt.out $(objpfx)tst-rtld-load-self.out
 endif
 tests-special += $(objpfx)check-textrel.out $(objpfx)check-execstack.out \
-                $(objpfx)check-localplt.out
+                $(objpfx)check-localplt.out $(objpfx)check-initfini.out
 endif
 
 ifeq ($(run-built-tests),yes)
@@ -1136,6 +1136,19 @@ $(objpfx)check-localplt.out: $(..)scripts/check-localplt.awk \
        $(evaluate-test)
 endif
 
+$(all-built-dso:=.dynsym): %.dynsym: %
+       @rm -f $@T
+       LC_ALL=C $(READELF) -W --dyn-syms $< > $@T
+       test -s $@T
+       mv -f $@T $@
+common-generated += $(all-built-dso:$(common-objpfx)%=%.dynsym)
+
+$(objpfx)check-initfini.out: $(..)scripts/check-initfini.awk \
+                           $(all-built-dso:=.dynsym)
+       LC_ALL=C $(AWK) -f $^ > $@; \
+       $(evaluate-test)
+generated += check-initfini.out
+
 $(objpfx)tst-dlopenrpathmod.so: $(libdl)
 $(objpfx)tst-dlopenrpath: $(objpfx)tst-dlopenrpathmod.so $(libdl)
 CFLAGS-tst-dlopenrpath.c += -DPFX=\"$(objpfx)\"
diff --git a/scripts/check-initfini.awk b/scripts/check-initfini.awk
new file mode 100644 (file)
index 0000000..19514a9
--- /dev/null
@@ -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);
+}
index 366b837d55b2ca518b801dffb65771971ec88546..2b213758b24203a44e9519a50eadc8408abde370 100644 (file)
@@ -72,6 +72,7 @@ call_weak_fn:
        .section .init,"ax",%progbits
        .align  2
        .global _init
+       .hidden _init
        .type   _init, %function
 _init:
        stp     x29, x30, [sp, -16]!
@@ -85,6 +86,7 @@ _init:
        .section        .fini,"ax",%progbits
        .align  2
        .global _fini
+       .hidden _fini
        .type   _fini, %function
 _fini:
        stp     x29, x30, [sp, -16]!
index b00ae203f5aba5f31918d568b9a297f3406776c5..bcce1e9055b2e1d405879e34db335f87dc4c0352 100644 (file)
@@ -67,6 +67,7 @@
 
        .section .init, "ax", @progbits
        .globl  _init
+       .hidden _init
        .type   _init, @function
        .usepv  _init, std
 _init:
@@ -89,6 +90,7 @@ _init:
 
        .section .fini, "ax", @progbits
        .globl  _fini
+       .hidden _fini
        .type   _fini,@function
        .usepv  _fini,std
 _fini:
index e645d467d396cba7936496a2225b7121509bc93b..a1424d033326d94368c2b512cb48950dfdec56bf 100644 (file)
@@ -78,6 +78,7 @@ call_weak_fn:
        .section .init,"ax",%progbits
        .p2align 2
        .globl _init
+       .hidden _init
        .type _init, %function
 _init:
        push    {r3, lr}
@@ -90,6 +91,7 @@ _init:
        .section .fini,"ax",%progbits
        .p2align 2
        .globl _fini
+       .hidden _fini
        .type _fini, %function
 _fini:
        push    {r3, lr}
index 4566d9f7da3c40519e14168aa5b2bc32fa7033a1..28550e57584a190b86f363b81d4034b43ed18c0f 100644 (file)
@@ -142,6 +142,7 @@ gmon_initializer:
        .section .init, "ax", %progbits
        .align 4
        .globl _init
+       .hidden _init
        .type _init,@function
 _init:
        stw     %rp,-20(%sp)
@@ -152,6 +153,7 @@ _init:
         .section .fini,"ax",%progbits
        .align 4
        .globl _fini
+       .hidden _fini
        .type _fini,@function
 _fini:
        stw     %rp,-20(%sp)
index 065460b813253561de247d9f5aaf90d6fa79715d..ffbc92c22f288d3d5667b6404ac0b788aac9ed96 100644 (file)
@@ -58,6 +58,7 @@
        .section .init,"ax",@progbits
        .p2align 2
        .globl _init
+       .hidden _init
        .type _init, @function
 _init:
        pushl %ebx
@@ -77,6 +78,7 @@ _init:
        .section .fini,"ax",@progbits
        .p2align 2
        .globl _fini
+       .hidden _fini
        .type _fini, @function
 _fini:
        pushl %ebx
index 867683b5ef78c3ee96b0ec6547f4b8e8a961f617..c46e297814205eb609ec31856ac8cb71bca9cdd6 100644 (file)
@@ -129,6 +129,7 @@ gmon_initializer:
 
        .section .init,"ax",@progbits
        .global _init#
+       .hidden _init#
        .proc _init#
 _init:
        .prologue
@@ -145,6 +146,7 @@ _init:
 
        .section .fini,"ax",@progbits
        .global _fini#
+       .hidden _fini#
        .proc _fini#
 _fini:
        .prologue
index b81076357c09596a930fbd9e0779434c286731e1..e5f2157cd6f892d4bb951533513caf35d5a27b66 100644 (file)
@@ -58,6 +58,7 @@
        .section .init,"ax",@progbits
        .align  2
        .globl  _init
+       .hidden _init
        .type   _init, @function
 _init:
        link.w %fp, #0
@@ -75,6 +76,7 @@ _init:
        .section .fini,"ax",@progbits
        .align  2
        .globl  _fini
+       .hidden _fini
        .type   _fini, @function
 _fini:
        link.w %fp, #0
index c407487b45df123effe93834e0100c943e175a1b..09c8cd7ccd2acd89648b53b66dbd5fa57cbcc621 100644 (file)
@@ -58,6 +58,7 @@
        .section .init,"ax",@progbits
        .align  2
        .globl  _init
+       .hidden _init
        .type   _init, @function
 _init:
        addik   r1,r1,-32
@@ -79,6 +80,7 @@ $Lno_weak_fn:
        .section .fini,"ax",@progbits
        .align  2
        .globl  _fini
+       .hidden _fini
        .type   _fini, @function
 _fini:
        addik   r1,r1,-32
index 139f8bb4ed9af26db37d0211a02d720c272103ea..b3e1c4e0d54636636bfd3f3b1b88b6848bb092c3 100644 (file)
@@ -65,6 +65,7 @@
        .section .init,"ax",@progbits
        .p2align 2
        .globl _init
+       .hidden _init
        .type _init, @function
 _init:
        .set noreorder
@@ -90,6 +91,7 @@ _init:
        .section .fini,"ax",@progbits
        .p2align 2
        .globl _fini
+       .hidden _fini
        .type _fini, @function
 _fini:
        .set noreorder
index 23ad90b59b22a2f2d1b3cf32513e17a9c35dd7f8..59a09d5763cf6b4a59e1fa21761b1a84962e7590 100644 (file)
@@ -65,6 +65,7 @@
        .section .init,"ax",@progbits
        .p2align 2
        .globl _init
+       .hidden _init
        .type _init, @function
 _init:
        addiu $sp,$sp,-16
@@ -90,6 +91,7 @@ _init:
        .section .fini,"ax",@progbits
        .p2align 2
        .globl _fini
+       .hidden _fini
        .type _fini, @function
 _fini:
        addiu $sp,$sp,-16
index 24b47b5cf3c494b0f9ce7298d5dcfd6fbfc0a38e..fd468f04672a962128aeb64718ffca39a7988453 100644 (file)
@@ -65,6 +65,7 @@
        .section .init,"ax",@progbits
        .p2align 2
        .globl _init
+       .hidden _init
        .type _init, @function
 _init:
        daddiu $sp,$sp,-16
@@ -90,6 +91,7 @@ _init:
        .section .fini,"ax",@progbits
        .p2align 2
        .globl _fini
+       .hidden _fini
        .type _fini, @function
 _fini:
        daddiu $sp,$sp,-16
index a3b42a4cc242e44bf6ee6effdc9887073043ceca..46ab896ac06d97a1fe774ab6c5b36f116ea8c410 100644 (file)
@@ -57,6 +57,7 @@
        .section .init,"ax",@progbits
        .align  2
        .global _init
+       .hidden _init
        .type   _init, @function
 _init:
        addi    sp, sp, -8
@@ -84,6 +85,7 @@ _init:
        .section .fini,"ax",@progbits
        .align  2
        .global _fini
+       .hidden _fini
        .type   _fini, @function
 _fini:
        addi    sp, sp, -8
index a30e33a75e6e173973320fe7eb92f3e73f2f7fc7..e4ee8dd484eb5f5321ce5a30284746c0a7cf9b97 100644 (file)
@@ -58,6 +58,7 @@
        .section .init,"ax",@progbits
        .align  2
        .globl  _init
+       .hidden _init
        .type   _init, @function
 _init:
        stwu r1, -16(r1)
@@ -80,6 +81,7 @@ _init:
        .section .fini,"ax",@progbits
        .align  2
        .globl  _fini
+       .hidden _fini
        .type   _fini, @function
 _fini:
        stwu r1, -16(r1)
index 61b1409a33649618993f44c04095260a54bdd887..2242deb3dd2bd92daa68d125b1c85076024639c2 100644 (file)
@@ -62,6 +62,7 @@
 #endif
        .section ".init", "ax", @progbits
        ENTRY_2(_init)
+       .hidden _init
        .align ALIGNARG (2)
 BODY_LABEL (_init):
        LOCALENTRY(_init)
@@ -80,6 +81,7 @@ BODY_LABEL (_init):
 
        .section ".fini", "ax", @progbits
        ENTRY_2(_fini)
+       .hidden _fini
        .align ALIGNARG (2)
 BODY_LABEL (_fini):
        LOCALENTRY(_fini)
index cb0c967de1720d80443d6e3832284e358a79c270..44b1a704fd66f5d6913bc60d5373fee95f4254f5 100644 (file)
@@ -57,6 +57,7 @@
 
        .section .init,"ax",@progbits
        .globl  _init
+       .hidden _init
        .type   _init,@function
        .align  4
 _init:
@@ -88,6 +89,7 @@ _init:
 
        .section .fini,"ax",@progbits
        .globl  _fini
+       .hidden _fini
        .type   _fini,@function
        .align  4
 _fini:
index 613bac217a443999f45fe9363e5f46d34ca0de8e..f676eb5259a4e966fefba1a88730c47d703f3f09 100644 (file)
@@ -59,6 +59,7 @@
        .section .init,"ax",@progbits
        .align 4
        .globl  _init
+       .hidden _init
        .type   _init,@function
 _init:
        stmg    %r6,%r15,48(%r15)
@@ -81,6 +82,7 @@ _init:
        .section .fini,"ax",@progbits
        .align 4
        .globl  _fini
+       .hidden _fini
        .type   _fini,@function
 _fini:
        stmg    %r6,%r15,48(%r15)
index 48f04a48b6889e4b468509be373a5cbce8689adb..c0707406f53e5b32d473a849a5fcad4aa87e3242 100644 (file)
@@ -58,6 +58,7 @@
        .section        .init,"ax",@progbits
        .align 5
        .global _init
+       .hidden _init
        .type   _init, @function
 _init:
        mov.l   r12,@-r15
@@ -103,6 +104,7 @@ _init:
        .section        .fini,"ax",@progbits
        .align 5
        .global _fini
+       .hidden _fini
        .type   _fini, @function
 _fini:
        mov.l   r12,@-r15
index 69aabe7e3b50821c77a55408a75928ee69b39060..a7d1a08acc03b8808eb4c1408839588d08095a24 100644 (file)
@@ -66,6 +66,7 @@
        .section        .init,"ax",@progbits
        .p2align        2
        .globl          _init
+       .hidden         _init
        .type           _init, @function
 _init:
        save            %sp, -STACKFRAME_SIZE, %sp
@@ -88,6 +89,7 @@ _init:
        .section        .fini,"ax",@progbits
        .p2align        2
        .globl          _fini
+       .hidden         _fini
        .type           _fini, @function
 _fini:
        save            %sp, -STACKFRAME_SIZE, %sp
index 619effac3a9050b014837a2fe2787c1cd41c23d2..f26915e95605e7492bb9dbb346b0362995461e22 100644 (file)
@@ -58,6 +58,7 @@
        .section .init,"ax",@progbits
        .p2align 2
        .globl _init
+       .hidden _init
        .type _init, @function
 _init:
        /* Maintain 16-byte stack alignment for called functions.  */
@@ -75,6 +76,7 @@ _init:
        .section .fini,"ax",@progbits
        .p2align 2
        .globl _fini
+       .hidden _fini
        .type _fini, @function
 _fini:
        subq $8, %rsp