Unlike other archs, mips64 needs ld.so to know about symbol visibility and
authorguenther <guenther@openbsd.org>
Thu, 18 Jan 2018 08:17:39 +0000 (08:17 +0000)
committerguenther <guenther@openbsd.org>
Thu, 18 Jan 2018 08:17:39 +0000 (08:17 +0000)
skip symbol lookup on protected symbols.  Add visibility #defines to
<sys/exec_elf.h> to support that.

ok kettenis@ visa@

libexec/ld.so/mips64/rtld_machine.c
sys/sys/exec_elf.h

index 528b1f3..fbc6d93 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rtld_machine.c,v 1.27 2017/01/30 05:00:31 guenther Exp $ */
+/*     $OpenBSD: rtld_machine.c,v 1.28 2018/01/18 08:17:39 guenther Exp $ */
 
 /*
  * Copyright (c) 1998-2004 Opsycon AB, Sweden.
@@ -235,8 +235,9 @@ _dl_md_reloc_got(elf_object_t *object, int lazy)
                            symp, object, NULL);
                        if (this)
                                *gotp = this->st_value + ooff;
-               } else if (ELF64_ST_TYPE(symp->st_info) == STT_FUNC &&
-                       symp->st_value != *gotp) {
+               } else if ((ELF64_ST_TYPE(symp->st_info) == STT_FUNC &&
+                       symp->st_value != *gotp) ||
+                       ELF_ST_VISIBILITY(symp->st_other) == STV_PROTECTED) {
                        *gotp += loff;
                } else {        /* Resolve all others immediately */
                        this = NULL;
index 817bfc6..141f9d4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: exec_elf.h,v 1.78 2017/12/09 06:35:08 deraadt Exp $   */
+/*     $OpenBSD: exec_elf.h,v 1.79 2018/01/18 08:17:39 guenther Exp $  */
 /*
  * Copyright (c) 1995, 1996 Erik Theisen.  All rights reserved.
  *
@@ -356,6 +356,16 @@ typedef struct {
 #define STT_LOPROC     13              /* reserved range for processor */
 #define STT_HIPROC     15              /*  specific symbol types */
 
+/* Extract symbol visibility - st_other */
+#define ELF_ST_VISIBILITY(v)           ((v) & 0x3)
+#define ELF32_ST_VISIBILITY            ELF_ST_VISIBILITY
+#define ELF64_ST_VISIBILITY            ELF_ST_VISIBILITY
+
+#define STV_DEFAULT    0               /* Visibility set by binding type */
+#define STV_INTERNAL   1               /* OS specific version of STV_HIDDEN */
+#define STV_HIDDEN     2               /* can only be seen inside own .so */
+#define STV_PROTECTED  3               /* HIDDEN inside, DEFAULT outside */
+
 /* Relocation entry with implicit addend */
 typedef struct {
        Elf32_Addr      r_offset;       /* offset of relocation */