tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Using hidden visibility in ld.elf_so



Hi all,
attached patch marks ld.elf_so as using hidden visibility by default and
the exported functions explicitly as public. It also changes i386 and
x86_64 to exploit this by using relative calls to avoid the PLT. This
slightly reduces the number of relocations and decreases size as well.

Comments? Test results?

Joerg
Index: Makefile
===================================================================
RCS file: /home/joerg/repo/netbsd/src/libexec/ld.elf_so/Makefile,v
retrieving revision 1.98
diff -u -p -r1.98 Makefile
--- Makefile    29 Oct 2010 15:08:17 -0000      1.98
+++ Makefile    3 Dec 2010 23:12:14 -0000
@@ -40,6 +40,7 @@ M=            ${.CURDIR}/arch/${ARCHSUBDIR}
 
 LDFLAGS+=      -shared -symbolic -nostartfiles
 LDFLAGS+=      -Wl,-static
+CFLAGS+=       -fvisibility=hidden
 
 # Adds SRCS, CPPFLAGS, LDFLAGS, etc.  Must go first so MD startup source
 # is first.
Index: rtld.h
===================================================================
RCS file: /home/joerg/repo/netbsd/src/libexec/ld.elf_so/rtld.h,v
retrieving revision 1.95
diff -u -p -r1.95 rtld.h
--- rtld.h      16 Oct 2010 10:27:07 -0000      1.95
+++ rtld.h      3 Dec 2010 23:05:11 -0000
@@ -254,13 +254,13 @@ extern Elf_Sym _rtld_sym_zero;
 /* rtld.c */
 
 /* We export these symbols using _rtld_symbol_lookup and is_exported. */
-char *dlerror(void);
-void *dlopen(const char *, int);
-void *dlsym(void *, const char *);
-int dlclose(void *);
-int dladdr(const void *, Dl_info *);
-int dlinfo(void *, int, void *);
-int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *),
+__dso_public char *dlerror(void);
+__dso_public void *dlopen(const char *, int);
+__dso_public void *dlsym(void *, const char *);
+__dso_public int dlclose(void *);
+__dso_public int dladdr(const void *, Dl_info *);
+__dso_public int dlinfo(void *, int, void *);
+__dso_public int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void 
*),
     void *);
 
 /* These aren't exported */
Index: arch/i386/rtld_start.S
===================================================================
RCS file: /home/joerg/repo/netbsd/src/libexec/ld.elf_so/arch/i386/rtld_start.S,v
retrieving revision 1.10
diff -u -p -r1.10 rtld_start.S
--- arch/i386/rtld_start.S      28 Apr 2008 20:23:03 -0000      1.10
+++ arch/i386/rtld_start.S      3 Dec 2010 23:18:04 -0000
@@ -34,6 +34,7 @@
        .text
        .align  4
        .globl  .rtld_start
+       .hidden .rtld_start
        .type   .rtld_start,@function
 .rtld_start:
        subl    $8,%esp                 # make room of obj_main and exit proc
@@ -48,12 +49,12 @@
 
        pushl   %ebx                    # relocbase
        pushl   %ecx                    # &_DYNAMIC
-       call    _rtld_relocate_nonplt_self@PLT
+       call    _rtld_relocate_nonplt_self
 
        leal    12(%esp),%eax           # &cleanup
        pushl   %ebx                    # relocbase
        pushl   %eax                    # sp
-       call    _rtld@PLT               # _rtld(sp, relocbase)
+       call    _rtld                   # _rtld(sp, relocbase)
 
        addl    $16,%esp                # pop args
 
@@ -64,6 +65,7 @@
 
        .align  4
        .globl  _rtld_bind_start
+       .hidden _rtld_bind_start
        .type   _rtld_bind_start,@function
 _rtld_bind_start:      # (obj, reloff)
        pushf                           # save registers
@@ -73,7 +75,7 @@ _rtld_bind_start:     # (obj, reloff)
 
        pushl   20(%esp)                # Copy of reloff
        pushl   20(%esp)                # Copy of obj
-       call    _rtld_bind@PLT          # Call the binder
+       call    _rtld_bind              # Call the binder
        addl    $8,%esp                 # pop binder args
        movl    %eax,20(%esp)           # Store function to be called in obj
 
Index: arch/x86_64/rtld_start.S
===================================================================
RCS file: 
/home/joerg/repo/netbsd/src/libexec/ld.elf_so/arch/x86_64/rtld_start.S,v
retrieving revision 1.7
diff -u -p -r1.7 rtld_start.S
--- arch/x86_64/rtld_start.S    3 Dec 2010 22:48:25 -0000       1.7
+++ arch/x86_64/rtld_start.S    3 Dec 2010 23:15:23 -0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: src/libexec/ld.elf_so/arch/x86_64/rtld_start.S,v 1.7 
2010-12-03 22:48:25 joerg Exp $   */
+/*     $NetBSD: rtld_start.S,v 1.7 2010/12/03 22:48:25 joerg Exp $     */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -40,6 +40,7 @@
        .text
        .align  16
        .globl  .rtld_start
+       .hidden .rtld_start
        .type   .rtld_start,@function
 .rtld_start:
        subq    $16,%rsp                # make room of obj_main and exit proc
@@ -52,11 +53,11 @@
        subq    (%rax),%rbx             # relocbase
 
        movq    %rbx,%rsi
-       call    _rtld_relocate_nonplt_self@PLT
+       call    _rtld_relocate_nonplt_self
 
        movq    %r12,%rdi
        movq    %rbx,%rsi
-       call    _rtld@PLT               # _rtld(sp, relocbase)
+       call    _rtld                   # _rtld(sp, relocbase)
 
        popq    %rbx                    # %rbx = ps_strings
        popq    %rdx                    # %rdx = cleanup
@@ -65,6 +66,7 @@
 
        .align  4
        .globl  _rtld_bind_start
+       .hidden _rtld_bind_start
        .type   _rtld_bind_start,@function
 _rtld_bind_start:      # (obj, reloff)
        # This function is called with a misaligned stack from the PLT
@@ -84,7 +86,7 @@ _rtld_bind_start:     # (obj, reloff)
        movq    80(%rsp),%rdi
        movq    88(%rsp),%rsi
 
-       call    _rtld_bind@PLT          # call the binder
+       call    _rtld_bind              # call the binder
        movq    %rax,88(%rsp)           # store function in obj
 
        popq    %r11


Home | Main Index | Thread Index | Old Index