summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
authorAli Bahrami <Ali.Bahrami@Sun.COM>2009-06-18 13:16:39 -0600
committerAli Bahrami <Ali.Bahrami@Sun.COM>2009-06-18 13:16:39 -0600
commit62b628a68db596a2d75a316dc7ffef658079231f (patch)
tree6d2f7ab582d82b5c1ab5f0214cc4e92b9cc2e2b7 /usr/src
parent60c682e1f62d3c131ea9130c21e0ccd86044e039 (diff)
downloadillumos-gate-62b628a68db596a2d75a316dc7ffef658079231f.tar.gz
6851224 elf_getshnum() and elf_getshstrndx() incompatible with 2002 ELF gABI agreement
PSARC/2009/363 replace elf_getphnum, elf_getshnum, and elf_getshstrndx
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/cmd/dis/dis_target.c6
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_gelf.c8
-rw-r--r--usr/src/cmd/mdb/common/mdb/mdb_target.c4
-rw-r--r--usr/src/cmd/sgs/dump/common/dump.c12
-rw-r--r--usr/src/cmd/sgs/elfdump/common/elfdump.c16
-rw-r--r--usr/src/cmd/sgs/elfdump/common/elfdump.msg6
-rw-r--r--usr/src/cmd/sgs/elfdump/common/fake_shdr.c4
-rw-r--r--usr/src/cmd/sgs/elfedit/common/elfedit.msg6
-rw-r--r--usr/src/cmd/sgs/elfedit/common/elfedit_machelf.c40
-rw-r--r--usr/src/cmd/sgs/libelf/common/gelf.c8
-rw-r--r--usr/src/cmd/sgs/libelf/common/getphnum.c40
-rw-r--r--usr/src/cmd/sgs/libelf/common/getshnum.c47
-rw-r--r--usr/src/cmd/sgs/libelf/common/getshstrndx.c40
-rw-r--r--usr/src/cmd/sgs/libelf/common/mapfile-common7
-rw-r--r--usr/src/cmd/sgs/libelf/demo/acom.c47
-rw-r--r--usr/src/cmd/sgs/libelf/demo/dcom.c92
-rw-r--r--usr/src/cmd/sgs/libelf/demo/dispsyms.c7
-rw-r--r--usr/src/cmd/sgs/libelf/demo/pcom.c30
-rw-r--r--usr/src/cmd/sgs/libelf/demo/tpcom.c42
-rw-r--r--usr/src/cmd/sgs/libld/common/globals.c8
-rw-r--r--usr/src/cmd/sgs/mcs/common/file.c10
-rw-r--r--usr/src/cmd/sgs/nm/common/nm.c2
-rw-r--r--usr/src/cmd/sgs/packages/common/SUNWonld-README3
-rw-r--r--usr/src/head/libelf.h7
-rw-r--r--usr/src/lib/libdtrace/common/dt_module.c12
-rw-r--r--usr/src/lib/libelfsign/common/elfsignlib.c6
-rw-r--r--usr/src/lib/libproc/common/Pcore.c6
-rw-r--r--usr/src/lib/libproc/common/Pidle.c4
-rw-r--r--usr/src/lib/libproc/common/Psymtab.c20
-rw-r--r--usr/src/uts/common/sys/elf.h3
30 files changed, 288 insertions, 255 deletions
diff --git a/usr/src/cmd/dis/dis_target.c b/usr/src/cmd/dis/dis_target.c
index ff6a74dcf5..e27a307bc0 100644
--- a/usr/src/cmd/dis/dis_target.c
+++ b/usr/src/cmd/dis/dis_target.c
@@ -20,12 +20,10 @@
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
@@ -390,7 +388,7 @@ dis_tgt_create(const char *file)
current->dt_elf = elf;
current->dt_arhdr = arhdr;
- if (elf_getshstrndx(elf, &current->dt_shstrndx) == -1) {
+ if (elf_getshdrstrndx(elf, &current->dt_shstrndx) == -1) {
warn("%s: failed to get section string table for "
"file", file);
dis_tgt_destroy(tgt);
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_gelf.c b/usr/src/cmd/mdb/common/mdb/mdb_gelf.c
index 8cedd78014..2272be41f6 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_gelf.c
+++ b/usr/src/cmd/mdb/common/mdb/mdb_gelf.c
@@ -927,7 +927,7 @@ gelf32_symtab_sort(mdb_gelf_symtab_t *gst)
static void
gelf32_symtab_init(mdb_gelf_symtab_t *gst)
{
-#if STT_NUM != (STT_IFUNC + 1)
+#if STT_NUM != (STT_TLS + 1)
#error "STT_NUM has grown. update gelf32_symtab_init()"
#endif
@@ -954,7 +954,7 @@ gelf32_symtab_init(mdb_gelf_symtab_t *gst)
const char *name = base + sym->st_name;
uchar_t type = ELF32_ST_TYPE(sym->st_info);
- if (type >= STT_IFUNC || type == STT_SECTION)
+ if (type >= STT_NUM || type == STT_SECTION)
continue; /* skip sections and unknown types */
if (sym->st_name >= ss_size || name[0] < '!' || name[0] > '~') {
@@ -1024,7 +1024,7 @@ gelf64_symtab_sort(mdb_gelf_symtab_t *gst)
static void
gelf64_symtab_init(mdb_gelf_symtab_t *gst)
{
-#if STT_NUM != (STT_IFUNC + 1)
+#if STT_NUM != (STT_TLS + 1)
#error "STT_NUM has grown. update gelf64_symtab_init()"
#endif
@@ -1051,7 +1051,7 @@ gelf64_symtab_init(mdb_gelf_symtab_t *gst)
const char *name = base + sym->st_name;
uchar_t type = ELF64_ST_TYPE(sym->st_info);
- if (type >= STT_IFUNC || type == STT_SECTION)
+ if (type >= STT_NUM || type == STT_SECTION)
continue; /* skip sections and unknown types */
if (sym->st_name >= ss_size || name[0] < '!' || name[0] > '~') {
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_target.c b/usr/src/cmd/mdb/common/mdb/mdb_target.c
index 8720ae080e..4319f6b27c 100644
--- a/usr/src/cmd/mdb/common/mdb/mdb_target.c
+++ b/usr/src/cmd/mdb/common/mdb/mdb_target.c
@@ -1902,7 +1902,7 @@ mdb_tgt_xdata_delete(mdb_tgt_t *t, const char *name)
int
mdb_tgt_sym_match(const GElf_Sym *sym, uint_t mask)
{
-#if STT_NUM != (STT_IFUNC + 1)
+#if STT_NUM != (STT_TLS + 1)
#error "STT_NUM has grown. update mdb_tgt_sym_match()"
#endif
@@ -1916,7 +1916,7 @@ mdb_tgt_sym_match(const GElf_Sym *sym, uint_t mask)
* in <sys/elf.h>. Changes to ELF must maintain binary
* compatibility, so I think this is reasonably fair game.
*/
- if (s_bind < STB_NUM && s_type < STT_IFUNC) {
+ if (s_bind < STB_NUM && s_type < STT_NUM) {
uint_t type = (1 << (s_type + 8)) | (1 << s_bind);
return ((type & ~mask) == 0);
}
diff --git a/usr/src/cmd/sgs/dump/common/dump.c b/usr/src/cmd/sgs/dump/common/dump.c
index 1e52465d1a..376f60b174 100644
--- a/usr/src/cmd/sgs/dump/common/dump.c
+++ b/usr/src/cmd/sgs/dump/common/dump.c
@@ -789,9 +789,9 @@ dump_reloc_table(Elf *elf_file, GElf_Ehdr *p_ehdr,
head_scns = p_head_scns;
- if (elf_getshnum(elf_file, &shnum) == 0) {
+ if (elf_getshdrnum(elf_file, &shnum) == -1) {
(void) fprintf(stderr,
- "%s: %s: elf_getshnum failed: %s\n",
+ "%s: %s: elf_getshdrnum failed: %s\n",
prog_name, filename, elf_errmsg(-1));
return;
}
@@ -1658,15 +1658,15 @@ dump_section_table(Elf *elf_file, GElf_Ehdr *elf_head_p, char *filename)
size_t shnum;
- if (elf_getshnum(elf_file, &shnum) == 0) {
+ if (elf_getshdrnum(elf_file, &shnum) == -1) {
(void) fprintf(stderr,
- "%s: %s: elf_getshnum failed: %s\n",
+ "%s: %s: elf_getshdrnum failed: %s\n",
prog_name, filename, elf_errmsg(-1));
return;
}
- if (elf_getshstrndx(elf_file, &shstrndx) == 0) {
+ if (elf_getshdrstrndx(elf_file, &shstrndx) == -1) {
(void) fprintf(stderr,
- "%s: %s: elf_getshstrndx failed: %s\n",
+ "%s: %s: elf_getshdrstrndx failed: %s\n",
prog_name, filename, elf_errmsg(-1));
return;
}
diff --git a/usr/src/cmd/sgs/elfdump/common/elfdump.c b/usr/src/cmd/sgs/elfdump/common/elfdump.c
index 12e4b603a3..a21d6a4b0a 100644
--- a/usr/src/cmd/sgs/elfdump/common/elfdump.c
+++ b/usr/src/cmd/sgs/elfdump/common/elfdump.c
@@ -1637,7 +1637,7 @@ output_symbol(SYMTBL_STATE *state, Word symndx, Word info, Word disp_symndx,
0, /* STT_FILE */
1, /* STT_COMMON */
0, /* STT_TLS */
- 0, /* STT_IFUNC */
+ 0, /* 7 */
0, /* 8 */
0, /* 9 */
0, /* 10 */
@@ -1647,7 +1647,7 @@ output_symbol(SYMTBL_STATE *state, Word symndx, Word info, Word disp_symndx,
0, /* 14 */
0, /* 15 */
};
-#if STT_NUM != (STT_IFUNC + 1)
+#if STT_NUM != (STT_TLS + 1)
#error "STT_NUM has grown. Update addr_symtype[]"
#endif
@@ -4218,18 +4218,18 @@ regular(const char *file, int fd, Elf *elf, uint_t flags,
return (ret);
}
- if (elf_getshnum(elf, &shnum) == 0) {
- failure(file, MSG_ORIG(MSG_ELF_GETSHNUM));
+ if (elf_getshdrnum(elf, &shnum) == -1) {
+ failure(file, MSG_ORIG(MSG_ELF_GETSHDRNUM));
return (ret);
}
- if (elf_getshstrndx(elf, &shstrndx) == 0) {
- failure(file, MSG_ORIG(MSG_ELF_GETSHSTRNDX));
+ if (elf_getshdrstrndx(elf, &shstrndx) == -1) {
+ failure(file, MSG_ORIG(MSG_ELF_GETSHDRSTRNDX));
return (ret);
}
- if (elf_getphnum(elf, &phnum) == 0) {
- failure(file, MSG_ORIG(MSG_ELF_GETPHNUM));
+ if (elf_getphdrnum(elf, &phnum) == -1) {
+ failure(file, MSG_ORIG(MSG_ELF_GETPHDRNUM));
return (ret);
}
/*
diff --git a/usr/src/cmd/sgs/elfdump/common/elfdump.msg b/usr/src/cmd/sgs/elfdump/common/elfdump.msg
index 1b86016158..8c254de9fb 100644
--- a/usr/src/cmd/sgs/elfdump/common/elfdump.msg
+++ b/usr/src/cmd/sgs/elfdump/common/elfdump.msg
@@ -304,9 +304,9 @@
@ MSG_ELF_GETARSYM "elf_getarsym"
@ MSG_ELF_RAND "elf_rand"
@ MSG_ELF_BEGIN "elf_begin"
-@ MSG_ELF_GETPHNUM "elf_getphnum"
-@ MSG_ELF_GETSHNUM "elf_getshnum"
-@ MSG_ELF_GETSHSTRNDX "elf_getshstrndx"
+@ MSG_ELF_GETPHDRNUM "elf_getphdrnum"
+@ MSG_ELF_GETSHDRNUM "elf_getshdrnum"
+@ MSG_ELF_GETSHDRSTRNDX "elf_getshdrstrndx"
@ MSG_ELF_XLATETOM "elf_xlatetom"
@ MSG_ELF_ARSYM "ARSYM"
diff --git a/usr/src/cmd/sgs/elfdump/common/fake_shdr.c b/usr/src/cmd/sgs/elfdump/common/fake_shdr.c
index 29f7bc1c99..4837a7f7a4 100644
--- a/usr/src/cmd/sgs/elfdump/common/fake_shdr.c
+++ b/usr/src/cmd/sgs/elfdump/common/fake_shdr.c
@@ -1122,8 +1122,8 @@ fake_shdr_cache(const char *file, int fd, Elf *elf, Ehdr *ehdr,
fstate.file = file;
fstate.fd = fd;
fstate.ehdr = ehdr;
- if (elf_getphnum(elf, &fstate.phnum) == 0) {
- failure(file, MSG_ORIG(MSG_ELF_GETPHNUM));
+ if (elf_getphdrnum(elf, &fstate.phnum) == -1) {
+ failure(file, MSG_ORIG(MSG_ELF_GETPHDRNUM));
return (0);
}
if ((fstate.phdr = elf_getphdr(elf)) == NULL) {
diff --git a/usr/src/cmd/sgs/elfedit/common/elfedit.msg b/usr/src/cmd/sgs/elfedit/common/elfedit.msg
index d3b2821d90..0f950c021f 100644
--- a/usr/src/cmd/sgs/elfedit/common/elfedit.msg
+++ b/usr/src/cmd/sgs/elfedit/common/elfedit.msg
@@ -592,12 +592,12 @@
@ MSG_ELF_BEGIN "elf_begin"
@ MSG_ELF_GETEHDR "elf_getehdr"
@ MSG_ELF_GETDATA "elf_getdata"
-@ MSG_ELF_GETPHNUM "elf_getphnum"
+@ MSG_ELF_GETPHDRNUM "elf_getphdrnum"
@ MSG_ELF_GETPHDR "elf_getphdr"
@ MSG_ELF_GETSCN "elf_getscn"
@ MSG_ELF_GETSHDR "elf_getshdr"
-@ MSG_ELF_GETSHNUM "elf_getshnum"
-@ MSG_ELF_GETSHSTRNDX "elf_getshstrndx"
+@ MSG_ELF_GETSHDRNUM "elf_getshdrnum"
+@ MSG_ELF_GETSHDRSTRNDX "elf_getshdrstrndx"
@ MSG_ELF_UPDATE "elf_update"
diff --git a/usr/src/cmd/sgs/elfedit/common/elfedit_machelf.c b/usr/src/cmd/sgs/elfedit/common/elfedit_machelf.c
index 6fe0e071ef..73653cd6e2 100644
--- a/usr/src/cmd/sgs/elfedit/common/elfedit_machelf.c
+++ b/usr/src/cmd/sgs/elfedit/common/elfedit_machelf.c
@@ -20,10 +20,9 @@
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
/*
* ELFCLASS specific code for elfedit, built once for each class
@@ -109,17 +108,19 @@ elfedit32_init_obj_state(const char *file, int fd, Elf *elf)
#define INITIAL_SYMTABNDX_ALLOC 5
/*
- * This macro is used to call functions from libelf, all of which
- * return NULL for failure and something else for success. On error,
- * libelf_fail_name is set and execution jumps to the libelf_failure
- * label for handling. Otherwise, the results of the call are ready
- * for use by the caller.
+ * These macros are used to call functions from libelf.
+ *
+ * LIBELF_FAIL encapsulates the common way in which we handle
+ * all of these errors: libelf_fail_name is set and execution
+ * jumps to the libelf_failure label for handling.
+ *
+ * LIBELF is used for the common case in which the function returns
+ * NULL for failure and something else for success.
*/
+#define LIBELF_FAIL(_name) { libelf_fail_name = _name; goto libelf_failure; }
#define LIBELF(_libelf_expr, _name) \
- if ((_libelf_expr) == NULL) { \
- libelf_fail_name = _name; \
- goto libelf_failure; \
- }
+ if ((_libelf_expr) == NULL) \
+ LIBELF_FAIL(_name)
const char *libelf_fail_name; /* Used for LIBELF errors */
@@ -146,8 +147,8 @@ elfedit32_init_obj_state(const char *file, int fd, Elf *elf)
MSG_ORIG(MSG_ELF_GETEHDR))
/* Program header array count and address */
- LIBELF(elf_getphnum(tstate.os_elf, &tstate.os_phnum),
- MSG_ORIG(MSG_ELF_GETPHNUM))
+ if (elf_getphdrnum(tstate.os_elf, &tstate.os_phnum) == -1)
+ LIBELF_FAIL(MSG_ORIG(MSG_ELF_GETPHDRNUM))
if (tstate.os_phnum > 0) {
LIBELF((tstate.os_phdr = elf_getphdr(tstate.os_elf)),
MSG_ORIG(MSG_ELF_GETPHDR))
@@ -155,17 +156,15 @@ elfedit32_init_obj_state(const char *file, int fd, Elf *elf)
tstate.os_phdr = NULL;
}
-
- LIBELF(elf_getshnum(tstate.os_elf, &tstate.os_shnum),
- MSG_ORIG(MSG_ELF_GETSHNUM))
-
+ if (elf_getshdrnum(tstate.os_elf, &tstate.os_shnum) == -1)
+ LIBELF_FAIL(MSG_ORIG(MSG_ELF_GETSHDRNUM))
/*
* Obtain the .shstrtab data buffer to provide the required section
* name strings.
*/
- LIBELF(elf_getshstrndx(tstate.os_elf, &tstate.os_shstrndx),
- MSG_ORIG(MSG_ELF_GETSHSTRNDX))
+ if (elf_getshdrstrndx(tstate.os_elf, &tstate.os_shstrndx) == -1)
+ LIBELF_FAIL(MSG_ORIG(MSG_ELF_GETSHDRSTRNDX))
LIBELF((scn = elf_getscn(tstate.os_elf, tstate.os_shstrndx)),
MSG_ORIG(MSG_ELF_GETSCN))
LIBELF((data = elf_getdata(scn, NULL)), MSG_ORIG(MSG_ELF_GETDATA))
@@ -448,6 +447,7 @@ libelf_failure:
free(obj_state);
(void) close(tstate.os_fd);
elfedit_elferr(tstate.os_file, libelf_fail_name);
-#undef LIBELF_FAILURE
#undef INITIAL_SYMTABNDX_ALLOC
+#undef LIBELF_FAIL
+#undef LIBELF
}
diff --git a/usr/src/cmd/sgs/libelf/common/gelf.c b/usr/src/cmd/sgs/libelf/common/gelf.c
index 0b3bd98566..9483826d90 100644
--- a/usr/src/cmd/sgs/libelf/common/gelf.c
+++ b/usr/src/cmd/sgs/libelf/common/gelf.c
@@ -19,12 +19,10 @@
* CDDL HEADER END
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <string.h>
#include "_libelf.h"
#include "decl.h"
@@ -223,7 +221,7 @@ gelf_getphdr(Elf *elf, int ndx, GElf_Phdr *dst)
if (elf == NULL)
return (NULL);
- if (elf_getphnum(elf, &phnum) == 0)
+ if (elf_getphdrnum(elf, &phnum) == -1)
return (NULL);
if (phnum <= ndx) {
@@ -270,7 +268,7 @@ gelf_update_phdr(Elf *elf, int ndx, GElf_Phdr *src)
if (elf == NULL)
return (0);
- if (elf_getphnum(elf, &phnum) == 0)
+ if (elf_getphdrnum(elf, &phnum) == -1)
return (NULL);
if (phnum < ndx) {
diff --git a/usr/src/cmd/sgs/libelf/common/getphnum.c b/usr/src/cmd/sgs/libelf/common/getphnum.c
index 914cb847b1..42d2a1769e 100644
--- a/usr/src/cmd/sgs/libelf/common/getphnum.c
+++ b/usr/src/cmd/sgs/libelf/common/getphnum.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,40 +19,59 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <string.h>
#include <gelf.h>
#include <decl.h>
#include <msg.h>
+/*
+ * Return number of entries in the program header array, taking
+ * extended headers into account.
+ *
+ * elf_getphnum() was defined based on the definition of the earlier
+ * elf_getshnum(). It returns 0 for failure, and 1 for success.
+ *
+ * elf_getphdrnum() supercedes elf_getphnum(), which is now considered
+ * obsolete. It returns -1 for failure and 0 for success, matching
+ * elf_getshdrnum(), and bringing us into alignment with the interface
+ * agreed to in the 2002 gABI meeting.
+ *
+ * See the comment in getshnum.c for additional information.
+ */
+
int
-elf_getphnum(Elf *elf, size_t *phnum)
+elf_getphdrnum(Elf *elf, size_t *phnum)
{
GElf_Ehdr ehdr;
Elf_Scn *scn;
GElf_Shdr shdr0;
if (gelf_getehdr(elf, &ehdr) == NULL)
- return (0);
+ return (-1);
if (ehdr.e_phnum != PN_XNUM) {
*phnum = ehdr.e_phnum;
- return (1);
+ return (0);
}
if ((scn = elf_getscn(elf, 0)) == NULL ||
gelf_getshdr(scn, &shdr0) == NULL)
- return (0);
+ return (-1);
if (shdr0.sh_info == 0)
*phnum = ehdr.e_phnum;
else
*phnum = shdr0.sh_info;
- return (1);
+ return (0);
+}
+
+int
+elf_getphnum(Elf *elf, size_t *phnum)
+{
+ return (elf_getphdrnum(elf, phnum) == 0);
}
diff --git a/usr/src/cmd/sgs/libelf/common/getshnum.c b/usr/src/cmd/sgs/libelf/common/getshnum.c
index 5279648362..77717a16b7 100644
--- a/usr/src/cmd/sgs/libelf/common/getshnum.c
+++ b/usr/src/cmd/sgs/libelf/common/getshnum.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,39 +19,61 @@
* CDDL HEADER END
*/
/*
- * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <string.h>
#include <gelf.h>
#include <decl.h>
#include <msg.h>
+/*
+ * Return number of entries in the section header array, taking
+ * extended headers into account.
+ *
+ * elf_getshnum() and elf_getshstrndx() were defined during the 2002 gABI
+ * meetings. They were supposed to return -1 for failure, and 0 for success.
+ * Our manpage documented them as such, but we then implemented them to
+ * return 0 for failure and 1 for success. This makes elf_getshnum() and
+ * elf_getshstrnum() non-portable to systems that implement the 2002 gABI
+ * definition.
+ *
+ * In 2005, the manpage was modified to match the code.
+ * In 2009, the discrepency was identified. elf_getshdrnum() and
+ * elf_getshdrstrndx() were created to provide a portable implementation.
+ * The older two functions are considered to be obsolete, and are retained
+ * for backward compatability.
+ */
+
int
-elf_getshnum(Elf *elf, size_t *shnum)
+elf_getshdrnum(Elf *elf, size_t *shnum)
{
GElf_Ehdr ehdr;
Elf_Scn *scn;
GElf_Shdr shdr0;
if (gelf_getehdr(elf, &ehdr) == 0)
- return (0);
+ return (-1);
if (ehdr.e_shnum > 0) {
*shnum = ehdr.e_shnum;
- return (1);
+ return (0);
}
if ((ehdr.e_shnum == 0) && (ehdr.e_shoff == 0)) {
*shnum = 0;
- return (1);
+ return (0);
}
if ((scn = elf_getscn(elf, 0)) == 0)
- return (0);
+ return (-1);
if (gelf_getshdr(scn, &shdr0) == 0)
- return (0);
+ return (-1);
*shnum = shdr0.sh_size;
- return (1);
+ return (0);
+}
+
+int
+elf_getshnum(Elf *elf, size_t *shnum)
+{
+ return (elf_getshdrnum(elf, shnum) == 0);
}
diff --git a/usr/src/cmd/sgs/libelf/common/getshstrndx.c b/usr/src/cmd/sgs/libelf/common/getshstrndx.c
index cea6446fbc..4b981c5fe4 100644
--- a/usr/src/cmd/sgs/libelf/common/getshstrndx.c
+++ b/usr/src/cmd/sgs/libelf/common/getshstrndx.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,34 +19,51 @@
* CDDL HEADER END
*/
/*
- * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <string.h>
#include <gelf.h>
#include <decl.h>
#include <msg.h>
+/*
+ * Return section header array string table index, taking
+ * extended headers into account.
+ *
+ * elf_getshstrndx() returns 0 for failure, and 1 for success.
+ *
+ * elf_getshdrstrndx() supercedes elf_getshstrndx(), which is now considered
+ * obsolete. It returns -1 for failure and 0 for success, bringing us into
+ * alignment with the interface agreed to in the 2002 gABI meeting.
+ *
+ * See the comment in getshnum.c for additional information.
+ */
+
int
-elf_getshstrndx(Elf *elf, size_t *shstrndx)
+elf_getshdrstrndx(Elf *elf, size_t *shstrndx)
{
GElf_Ehdr ehdr;
Elf_Scn *scn;
GElf_Shdr shdr0;
if (gelf_getehdr(elf, &ehdr) == 0)
- return (0);
+ return (-1);
if (ehdr.e_shstrndx != SHN_XINDEX) {
*shstrndx = ehdr.e_shstrndx;
- return (1);
+ return (0);
}
if ((scn = elf_getscn(elf, 0)) == 0)
- return (0);
+ return (-1);
if (gelf_getshdr(scn, &shdr0) == 0)
- return (0);
+ return (-1);
*shstrndx = shdr0.sh_link;
- return (1);
+ return (0);
+}
+
+int
+elf_getshstrndx(Elf *elf, size_t *shstrndx)
+{
+ return (elf_getshdrstrndx(elf, shstrndx) == 0);
}
diff --git a/usr/src/cmd/sgs/libelf/common/mapfile-common b/usr/src/cmd/sgs/libelf/common/mapfile-common
index 9612e850af..f53cc931b5 100644
--- a/usr/src/cmd/sgs/libelf/common/mapfile-common
+++ b/usr/src/cmd/sgs/libelf/common/mapfile-common
@@ -37,6 +37,13 @@
# MAPFILE HEADER END
#
+SUNW_1.7 {
+ global:
+ elf_getphdrnum;
+ elf_getshdrnum;
+ elf_getshdrstrndx;
+} SUNW_1.6;
+
SUNW_1.6 {
global:
elf_getphnum;
diff --git a/usr/src/cmd/sgs/libelf/demo/acom.c b/usr/src/cmd/sgs/libelf/demo/acom.c
index 607e441b95..b5b1317d52 100644
--- a/usr/src/cmd/sgs/libelf/demo/acom.c
+++ b/usr/src/cmd/sgs/libelf/demo/acom.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,10 +19,9 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
/*
* acom: Append Comment
@@ -53,9 +51,9 @@ update_comment(Elf *elf, const char *file, const char *comment)
Elf_Data *data;
size_t shstrndx;
- if (elf_getshstrndx(elf, &shstrndx) == 0) {
- (void) fprintf(stderr, "%s: gelf_getshstrdx() failed: %s\n",
- file, elf_errmsg(0));
+ if (elf_getshdrstrndx(elf, &shstrndx) == -1) {
+ (void) fprintf(stderr, "%s: gelf_getshdrstrdx() failed: %s\n",
+ file, elf_errmsg(0));
return;
}
@@ -66,9 +64,8 @@ update_comment(Elf *elf, const char *file, const char *comment)
* this is the section we want to process.
*/
if (gelf_getshdr(scn, &shdr) == 0) {
- (void) fprintf(stderr,
- "%s: elf_getshdr() failed: %s\n",
- file, elf_errmsg(0));
+ (void) fprintf(stderr, "%s: elf_getshdr() failed: %s\n",
+ file, elf_errmsg(0));
return;
}
if (strcmp(CommentStr, elf_strptr(elf, shstrndx,
@@ -80,24 +77,24 @@ update_comment(Elf *elf, const char *file, const char *comment)
int ndx;
(void) printf("%s has no .comment section. "
- "Creating one...\n", file);
+ "Creating one...\n", file);
/*
* First add the ".comment" string to the string table
*/
if ((scn = elf_getscn(elf, shstrndx)) == 0) {
(void) fprintf(stderr, "%s: elf_getscn() failed: %s\n",
- file, elf_errmsg(0));
+ file, elf_errmsg(0));
return;
}
if ((data = elf_getdata(scn, 0)) == 0) {
(void) fprintf(stderr, "%s: elf_getdata() failed: %s\n",
- file, elf_errmsg(0));
+ file, elf_errmsg(0));
return;
}
ndx = data->d_off + data->d_size;
if ((data = elf_newdata(scn)) == 0) {
(void) fprintf(stderr, "%s: elf_newdata() failed: %s\n",
- file, elf_errmsg(0));
+ file, elf_errmsg(0));
return;
}
data->d_buf = (void *)CommentStr;
@@ -111,13 +108,12 @@ update_comment(Elf *elf, const char *file, const char *comment)
*/
if ((scn = elf_newscn(elf)) == 0) {
(void) fprintf(stderr, "%s: elf_newscn() failed: %s\n",
- file, elf_errmsg(0));
+ file, elf_errmsg(0));
return;
}
if (gelf_getshdr(scn, &shdr) == 0) {
- (void) fprintf(stderr,
- "%s: elf_getshdr() failed: %s\n",
- file, elf_errmsg(0));
+ (void) fprintf(stderr, "%s: elf_getshdr() failed: %s\n",
+ file, elf_errmsg(0));
return;
}
shdr.sh_name = ndx;
@@ -136,13 +132,13 @@ update_comment(Elf *elf, const char *file, const char *comment)
if (shdr.sh_addr != 0) {
(void) printf("%s: .comment section is part of a "
- "loadable segment, it cannot be changed.\n", file);
+ "loadable segment, it cannot be changed.\n", file);
return;
}
if ((data = elf_newdata(scn)) == 0) {
(void) fprintf(stderr, "%s: elf_getdata() failed: %s\n",
- file, elf_errmsg(0));
+ file, elf_errmsg(0));
return;
}
data->d_buf = (void *)comment;
@@ -151,7 +147,7 @@ update_comment(Elf *elf, const char *file, const char *comment)
if (elf_update(elf, ELF_C_WRITE) == -1)
(void) fprintf(stderr, "%s: elf_update() failed: %s\n", file,
- elf_errmsg(0));
+ elf_errmsg(0));
}
@@ -164,7 +160,7 @@ main(int argc, char **argv)
if (argc < 3) {
(void) printf("usage: %s <new comment> elf_file ...\n",
- argv[0]);
+ argv[0]);
return (1);
}
@@ -174,7 +170,7 @@ main(int argc, char **argv)
*/
if (elf_version(EV_CURRENT) == EV_NONE) {
(void) fprintf(stderr, "elf_version() failed: %s\n",
- elf_errmsg(0));
+ elf_errmsg(0));
return (1);
}
@@ -212,8 +208,7 @@ main(int argc, char **argv)
update_comment(elf, elf_fname, new_comment);
else
(void) printf("%s not of type ELF_K_ELF. "
- "elf_kind == %d\n",
- elf_fname, elf_kind(elf));
+ "elf_kind == %d\n", elf_fname, elf_kind(elf));
(void) elf_end(elf);
(void) close(fd);
diff --git a/usr/src/cmd/sgs/libelf/demo/dcom.c b/usr/src/cmd/sgs/libelf/demo/dcom.c
index 35c9c710c7..79dffb619b 100644
--- a/usr/src/cmd/sgs/libelf/demo/dcom.c
+++ b/usr/src/cmd/sgs/libelf/demo/dcom.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,10 +19,9 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
/*
@@ -109,25 +107,25 @@ delete_comment(Elf *elf, int fd, const char *file)
if (gelf_getehdr(elf, &ehdr) == 0) {
(void) fprintf(stderr, "%s: elf_getehdr() failed: %s\n",
- file, elf_errmsg(0));
+ file, elf_errmsg(0));
return;
}
- if (elf_getshnum(elf, &shnum) == 0) {
- (void) fprintf(stderr, "%s: elf_getshnum() failed: %s\n",
- file, elf_errmsg(0));
+ if (elf_getshdrnum(elf, &shnum) == -1) {
+ (void) fprintf(stderr, "%s: elf_getshdrnum() failed: %s\n",
+ file, elf_errmsg(0));
return;
}
- if (elf_getshstrndx(elf, &shstrndx) == 0) {
- (void) fprintf(stderr, "%s: elf_getshstrndx() failed: %s\n",
- file, elf_errmsg(0));
+ if (elf_getshdrstrndx(elf, &shstrndx) == -1) {
+ (void) fprintf(stderr, "%s: elf_getshdrstrndx() failed: %s\n",
+ file, elf_errmsg(0));
return;
}
- if (elf_getphnum(elf, &phnum) == 0) {
- (void) fprintf(stderr, "%s: elf_getphnum() failed: %s\n",
- file, elf_errmsg(0));
+ if (elf_getphdrnum(elf, &phnum) == -1) {
+ (void) fprintf(stderr, "%s: elf_getphdrnum() failed: %s\n",
+ file, elf_errmsg(0));
return;
}
@@ -146,9 +144,8 @@ delete_comment(Elf *elf, int fd, const char *file)
* this is the section we want to process.
*/
if (gelf_getshdr(scn, &shdr) == 0) {
- (void) fprintf(stderr,
- "%s: elf_getshdr() failed: %s\n",
- file, elf_errmsg(0));
+ (void) fprintf(stderr, "%s: elf_getshdr() failed: %s\n",
+ file, elf_errmsg(0));
free(shndx);
return;
}
@@ -164,8 +161,8 @@ delete_comment(Elf *elf, int fd, const char *file)
*/
if (shdr.sh_addr != 0) {
(void) printf("%s: .comment section is "
- "part of a loadable segment, it "
- "cannot be deleted.\n", file);
+ "part of a loadable segment, it "
+ "cannot be deleted.\n", file);
free(shndx);
return;
}
@@ -195,13 +192,13 @@ delete_comment(Elf *elf, int fd, const char *file)
if (gelf_newehdr(telf, gelf_getclass(elf)) == 0) {
(void) fprintf(stderr, "%s: elf_newehdr() failed: %s\n",
- file, elf_errmsg(0));
+ file, elf_errmsg(0));
free(shndx);
return;
}
if (gelf_getehdr(telf, &tehdr) == 0) {
(void) fprintf(stderr, "%s: elf_getehdr() failed: %s\n",
- file, elf_errmsg(0));
+ file, elf_errmsg(0));
free(shndx);
return;
}
@@ -225,23 +222,20 @@ delete_comment(Elf *elf, int fd, const char *file)
* new file.
*/
if (gelf_getshdr(scn, &shdr) == 0) {
- (void) fprintf(stderr,
- "%s: elf_getshdr() failed: %s\n",
- file, elf_errmsg(0));
+ (void) fprintf(stderr, "%s: elf_getshdr() failed: %s\n",
+ file, elf_errmsg(0));
free(shndx);
return;
}
if ((tscn = elf_newscn(telf)) == 0) {
- (void) fprintf(stderr,
- "%s: elf_newscn() failed: %s\n",
- file, elf_errmsg(0));
+ (void) fprintf(stderr, "%s: elf_newscn() failed: %s\n",
+ file, elf_errmsg(0));
free(shndx);
return;
}
if (gelf_getshdr(tscn, &tshdr) == 0) {
- (void) fprintf(stderr,
- "%s: elf_getshdr() failed: %s\n",
- file, elf_errmsg(0));
+ (void) fprintf(stderr, "%s: elf_getshdr() failed: %s\n",
+ file, elf_errmsg(0));
free(shndx);
return;
}
@@ -268,16 +262,14 @@ delete_comment(Elf *elf, int fd, const char *file)
gelf_update_shdr(tscn, &tshdr);
if ((data = elf_getdata(scn, 0)) == 0) {
- (void) fprintf(stderr,
- "%s: elf_getdata() failed: %s\n",
- file, elf_errmsg(0));
+ (void) fprintf(stderr, "%s: elf_getdata() failed: %s\n",
+ file, elf_errmsg(0));
free(shndx);
return;
}
if ((tdata = elf_newdata(tscn)) == 0) {
- (void) fprintf(stderr,
- "%s: elf_newdata() failed: %s\n",
- file, elf_errmsg(0));
+ (void) fprintf(stderr, "%s: elf_newdata() failed: %s\n",
+ file, elf_errmsg(0));
free(shndx);
return;
}
@@ -296,16 +288,14 @@ delete_comment(Elf *elf, int fd, const char *file)
* store the shstrndx in Shdr[0].sh_link
*/
if ((_scn = elf_getscn(telf, 0)) == 0) {
- (void) fprintf(stderr,
- "%s: elf_getscn() failed: %s\n",
- file, elf_errmsg(0));
+ (void) fprintf(stderr, "%s: elf_getscn() failed: %s\n",
+ file, elf_errmsg(0));
free(shndx);
return;
}
if (gelf_getshdr(_scn, &shdr0) == 0) {
- (void) fprintf(stderr,
- "%s: elf_getshdr() failed: %s\n",
- file, elf_errmsg(0));
+ (void) fprintf(stderr, "%s: elf_getshdr() failed: %s\n",
+ file, elf_errmsg(0));
free(shndx);
return;
}
@@ -322,17 +312,16 @@ delete_comment(Elf *elf, int fd, const char *file)
*/
if (phnum != 0) {
if (gelf_newphdr(telf, phnum) == 0) {
- (void) fprintf(stderr,
- "%s: elf_newphdr() failed: %s\n",
- file, elf_errmsg(0));
+ (void) fprintf(stderr, "%s: elf_newphdr() failed: %s\n",
+ file, elf_errmsg(0));
return;
}
for (ndx = 0; ndx < (int)phnum; ndx++) {
if (gelf_getphdr(elf, ndx, &phdr) == 0 ||
gelf_getphdr(telf, ndx, &tphdr) == 0) {
(void) fprintf(stderr,
- "%s: elf_getphdr() failed: %s\n",
- file, elf_errmsg(0));
+ "%s: elf_getphdr() failed: %s\n",
+ file, elf_errmsg(0));
return;
}
tphdr = phdr;
@@ -347,7 +336,7 @@ delete_comment(Elf *elf, int fd, const char *file)
*/
if (elf_update(telf, ELF_C_WRITE) == -1) {
(void) fprintf(stderr, "elf_update() failed: %s\n",
- elf_errmsg(0));
+ elf_errmsg(0));
(void) elf_end(telf);
(void) close(tfd);
return;
@@ -387,7 +376,7 @@ main(int argc, char ** argv)
*/
if (elf_version(EV_CURRENT) == EV_NONE) {
(void) fprintf(stderr, "elf_version() failed: %s\n",
- elf_errmsg(0));
+ elf_errmsg(0));
return (1);
}
@@ -423,8 +412,7 @@ main(int argc, char ** argv)
* ELF files.
*/
(void) printf("%s not of type ELF_K_ELF. "
- "elf_kind == %d\n",
- elf_fname, elf_kind(elf));
+ "elf_kind == %d\n", elf_fname, elf_kind(elf));
} else
delete_comment(elf, fd, elf_fname);
diff --git a/usr/src/cmd/sgs/libelf/demo/dispsyms.c b/usr/src/cmd/sgs/libelf/demo/dispsyms.c
index 95a4304be8..b6fcdc52ce 100644
--- a/usr/src/cmd/sgs/libelf/demo/dispsyms.c
+++ b/usr/src/cmd/sgs/libelf/demo/dispsyms.c
@@ -61,9 +61,8 @@ static const char *symtype[STT_NUM] = {
/* STT_FILE */ "FILE",
/* STT_COMMON */ "COMM",
/* STT_TLS */ "TLS"
-/* STT_IFUNC */ "IFUNC"
};
-#if STT_NUM != (STT_IFUNC + 1)
+#if STT_NUM != (STT_TLS + 1)
#error "STT_NUM has grown. Update symtype[]."
#endif
@@ -85,8 +84,8 @@ print_symtab(Elf *elf, const char *file)
return;
}
- if (elf_getshstrndx(elf, &shstrndx) == 0) {
- (void) fprintf(stderr, "%s: elf_getshstrndx() failed: %s\n",
+ if (elf_getshdrstrndx(elf, &shstrndx) == -1) {
+ (void) fprintf(stderr, "%s: elf_getshdrstrndx() failed: %s\n",
file, elf_errmsg(0));
return;
}
diff --git a/usr/src/cmd/sgs/libelf/demo/pcom.c b/usr/src/cmd/sgs/libelf/demo/pcom.c
index bf44f08f8b..36e7354caa 100644
--- a/usr/src/cmd/sgs/libelf/demo/pcom.c
+++ b/usr/src/cmd/sgs/libelf/demo/pcom.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -34,8 +33,6 @@
* contents will be displayed on stdout.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <stdio.h>
#include <libelf.h>
#include <gelf.h>
@@ -58,9 +55,9 @@ print_comment(Elf *elf, const char *file)
(void) printf("%s .comment:\n", file);
- if (elf_getshstrndx(elf, &shstrndx) == 0) {
- (void) fprintf(stderr, "%s: elf_getshstrndx() failed: %s\n",
- file, elf_errmsg(0));
+ if (elf_getshdrstrndx(elf, &shstrndx) == -1) {
+ (void) fprintf(stderr, "%s: elf_getshdrstrndx() failed: %s\n",
+ file, elf_errmsg(0));
return;
}
@@ -71,9 +68,8 @@ print_comment(Elf *elf, const char *file)
* this is the section we want to process.
*/
if (gelf_getshdr(scn, &shdr) == 0) {
- (void) fprintf(stderr,
- "%s: elf_getshdr() failed: %s\n",
- file, elf_errmsg(0));
+ (void) fprintf(stderr, "%s: elf_getshdr() failed: %s\n",
+ file, elf_errmsg(0));
return;
}
if (strcmp(CommentStr, elf_strptr(elf, shstrndx,
@@ -87,8 +83,8 @@ print_comment(Elf *elf, const char *file)
*/
if ((data = elf_getdata(scn, 0)) == 0) {
(void) fprintf(stderr,
- "%s: elf_getdata() failed: %s\n",
- file, elf_errmsg(0));
+ "%s: elf_getdata() failed: %s\n",
+ file, elf_errmsg(0));
return;
}
/*
@@ -155,8 +151,8 @@ process_elf(Elf *elf, char *file, int fd, int member)
default:
if (!member)
(void) fprintf(stderr,
- "%s: unexpected elf_kind(): 0x%x\n",
- file, elf_kind(elf));
+ "%s: unexpected elf_kind(): 0x%x\n",
+ file, elf_kind(elf));
return;
}
}
@@ -178,7 +174,7 @@ main(int argc, char **argv)
*/
if (elf_version(EV_CURRENT) == EV_NONE) {
(void) fprintf(stderr,
- "elf_version() failed: %s\n", elf_errmsg(0));
+ "elf_version() failed: %s\n", elf_errmsg(0));
return (1);
}
diff --git a/usr/src/cmd/sgs/libelf/demo/tpcom.c b/usr/src/cmd/sgs/libelf/demo/tpcom.c
index 5359cd3376..206bcfd759 100644
--- a/usr/src/cmd/sgs/libelf/demo/tpcom.c
+++ b/usr/src/cmd/sgs/libelf/demo/tpcom.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,12 +19,10 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
/*
* tpcom: Threaded Print Comment
*
@@ -77,9 +74,9 @@ print_comment(Elf *elf, const char *file)
size_t shstrndx;
- if (elf_getshstrndx(elf, &shstrndx) == 0) {
- (void) fprintf(stderr, "%s: elf_getshstrndx() failed: %s\n",
- file, elf_errmsg(0));
+ if (elf_getshdrstrndx(elf, &shstrndx) == -1) {
+ (void) fprintf(stderr, "%s: elf_getshdrstrndx() failed: %s\n",
+ file, elf_errmsg(0));
return;
}
while ((scn = elf_nextscn(elf, scn)) != 0) {
@@ -89,9 +86,8 @@ print_comment(Elf *elf, const char *file)
* this is the section we want to process.
*/
if (gelf_getshdr(scn, &shdr) == 0) {
- (void) fprintf(stderr,
- "%s: elf_getshdr() failed: %s\n",
- file, elf_errmsg(0));
+ (void) fprintf(stderr, "%s: elf_getshdr() failed: %s\n",
+ file, elf_errmsg(0));
return;
}
@@ -109,8 +105,8 @@ print_comment(Elf *elf, const char *file)
*/
if ((data = elf_getdata(scn, 0)) == 0) {
(void) fprintf(stderr,
- "%s: elf_getdata() failed: %s\n",
- file, elf_errmsg(0));
+ "%s: elf_getdata() failed: %s\n",
+ file, elf_errmsg(0));
mutex_unlock(&printlock);
return;
}
@@ -153,23 +149,23 @@ process_elf(pe_args * pep)
if ((arhdr = elf_getarhdr(_elf)) == 0) {
(void) fprintf(stderr,
- "%s: elf_getarhdr() failed: %s\n",
- pep->pe_file, elf_errmsg(0));
+ "%s: elf_getarhdr() failed: %s\n",
+ pep->pe_file, elf_errmsg(0));
}
cmd = elf_next(_elf);
_pep = malloc(sizeof (pe_args));
_pep->pe_elf = _elf;
_pep->pe_file = malloc(strlen(pep->pe_file) +
- strlen(arhdr->ar_name) + 5);
+ strlen(arhdr->ar_name) + 5);
(void) sprintf(_pep->pe_file,
- "%s(%s)", pep->pe_file, arhdr->ar_name);
+ "%s(%s)", pep->pe_file, arhdr->ar_name);
_pep->pe_fd = pep->pe_fd;
_pep->pe_member = 1;
if ((rc = thr_create(NULL, 0,
(void *(*)(void *))process_elf,
(void *)_pep, THR_DETACHED, 0)) != 0) {
(void) fprintf(stderr,
- "thr_create() failed, rc = %d\n", rc);
+ "thr_create() failed, rc = %d\n", rc);
}
}
break;
@@ -177,8 +173,8 @@ process_elf(pe_args * pep)
if (!pep->pe_member) {
mutex_lock(&printlock);
(void) fprintf(stderr,
- "%s: unexpected elf_kind(): 0x%x\n",
- pep->pe_file, elf_kind(pep->pe_elf));
+ "%s: unexpected elf_kind(): 0x%x\n",
+ pep->pe_file, elf_kind(pep->pe_elf));
mutex_unlock(&printlock);
}
}
@@ -207,7 +203,7 @@ main(int argc, char ** argv)
*/
if (elf_version(EV_CURRENT) == EV_NONE) {
(void) fprintf(stderr,
- "elf_version() failed: %s\n", elf_errmsg(0));
+ "elf_version() failed: %s\n", elf_errmsg(0));
return (1);
}
@@ -255,7 +251,7 @@ main(int argc, char ** argv)
(void *)pep, THR_DETACHED, 0)) != 0) {
mutex_lock(&printlock);
(void) fprintf(stderr,
- "thr_create() failed with code: %d\n", rc);
+ "thr_create() failed with code: %d\n", rc);
mutex_unlock(&printlock);
return (1);
}
diff --git a/usr/src/cmd/sgs/libld/common/globals.c b/usr/src/cmd/sgs/libld/common/globals.c
index ba1ac96ef1..1709f2e837 100644
--- a/usr/src/cmd/sgs/libld/common/globals.c
+++ b/usr/src/cmd/sgs/libld/common/globals.c
@@ -89,7 +89,7 @@ ldynsym_symtype[] = {
1, /* STT_FILE */
0, /* STT_COMMON */
0, /* STT_TLS */
- 0, /* STT_IFUNC */
+ 0, /* 7 */
0, /* 8 */
0, /* 9 */
0, /* 10 */
@@ -99,7 +99,7 @@ ldynsym_symtype[] = {
0, /* 14 */
0, /* 15 */
};
-#if STT_NUM != (STT_IFUNC + 1)
+#if STT_NUM != (STT_TLS + 1)
#error "STT_NUM has grown. Update ldynsym_symtype[]."
#endif
@@ -116,7 +116,7 @@ dynsymsort_symtype[] = {
0, /* STT_FILE */
1, /* STT_COMMON */
0, /* STT_TLS */
- 0, /* STT_IFUNC */
+ 0, /* 7 */
0, /* 8 */
0, /* 9 */
0, /* 10 */
@@ -126,6 +126,6 @@ dynsymsort_symtype[] = {
0, /* 14 */
0, /* 15 */
};
-#if STT_NUM != (STT_IFUNC + 1)
+#if STT_NUM != (STT_TLS + 1)
#error "STT_NUM has grown. Update dynsymsort_symtype[]."
#endif
diff --git a/usr/src/cmd/sgs/mcs/common/file.c b/usr/src/cmd/sgs/mcs/common/file.c
index 4ddce92c7d..2d9eca56b9 100644
--- a/usr/src/cmd/sgs/mcs/common/file.c
+++ b/usr/src/cmd/sgs/mcs/common/file.c
@@ -258,7 +258,7 @@ process_file(Elf *elf, char *cur_file, Cmd_Info *cmd_info)
return (FAILURE);
}
- if (elf_getshnum(elf, &shnum) == NULL) {
+ if (elf_getshdrnum(elf, &shnum) == -1) {
error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog);
return (FAILURE);
}
@@ -328,11 +328,11 @@ traverse_file(Elf *elf, GElf_Ehdr * ehdr, char *cur_file, Cmd_Info *cmd_info,
state->Sect_exists = 0;
- if (elf_getshnum(elf, &shnum) == NULL) {
+ if (elf_getshdrnum(elf, &shnum) == -1) {
error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog);
return (FAILURE);
}
- if (elf_getshstrndx(elf, &shstrndx) == NULL) {
+ if (elf_getshdrstrndx(elf, &shstrndx) == -1) {
error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog);
return (FAILURE);
}
@@ -693,11 +693,11 @@ build_file(Elf *src_elf, GElf_Ehdr *src_ehdr, Cmd_Info *cmd_info,
size_t shnum, shstrndx;
- if (elf_getshnum(src_elf, &shnum) == NULL) {
+ if (elf_getshdrnum(src_elf, &shnum) == -1) {
error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog);
return (FAILURE);
}
- if (elf_getshstrndx(src_elf, &shstrndx) == NULL) {
+ if (elf_getshdrstrndx(src_elf, &shstrndx) == -1) {
error_message(LIBELF_ERROR, LIBelf_ERROR, elf_errmsg(-1), prog);
return (FAILURE);
}
diff --git a/usr/src/cmd/sgs/nm/common/nm.c b/usr/src/cmd/sgs/nm/common/nm.c
index 943356e6d4..c5d51f9641 100644
--- a/usr/src/cmd/sgs/nm/common/nm.c
+++ b/usr/src/cmd/sgs/nm/common/nm.c
@@ -538,7 +538,7 @@ get_symtab(Elf *elf_file, char *filename)
GElf_Word symtabtype;
size_t shstrndx;
- if (elf_getshstrndx(elf_file, &shstrndx) == 0) {
+ if (elf_getshdrstrndx(elf_file, &shstrndx) == -1) {
(void) fprintf(stderr, gettext(
"%s: %s: could not get e_shstrndx\n"),
prog_name, filename);
diff --git a/usr/src/cmd/sgs/packages/common/SUNWonld-README b/usr/src/cmd/sgs/packages/common/SUNWonld-README
index 1cf82ac30d..55d53bbaa2 100644
--- a/usr/src/cmd/sgs/packages/common/SUNWonld-README
+++ b/usr/src/cmd/sgs/packages/common/SUNWonld-README
@@ -1485,3 +1485,6 @@ Bugid Risk Synopsis
6784790 ld should examine archives to determine output object class/machine
PSARC/2009/305 ld -32 option
6849998 remove undocumented mapfile $SPECVERS and $NEED options
+6851224 elf_getshnum() and elf_getshstrndx() incompatible with 2002 ELF gABI
+ agreement
+ PSARC/2009/363 replace elf_getphnum, elf_getshnum, and elf_getshstrndx
diff --git a/usr/src/head/libelf.h b/usr/src/head/libelf.h
index 394b8ce3e9..8929924ad9 100644
--- a/usr/src/head/libelf.h
+++ b/usr/src/head/libelf.h
@@ -22,15 +22,13 @@
/* All Rights Reserved */
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _LIBELF_H
#define _LIBELF_H
-#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.9 */
-
#include <sys/types.h>
#include <sys/elf.h>
@@ -191,8 +189,11 @@ Elf32_Phdr *elf32_getphdr _((Elf *));
Elf_Scn *elf_getscn _((Elf *elf, size_t));
Elf32_Shdr *elf32_getshdr _((Elf_Scn *));
int elf_getphnum _((Elf *, size_t *));
+int elf_getphdrnum _((Elf *, size_t *));
int elf_getshnum _((Elf *, size_t *));
+int elf_getshdrnum _((Elf *, size_t *));
int elf_getshstrndx _((Elf *, size_t *));
+int elf_getshdrstrndx _((Elf *, size_t *));
unsigned long elf_hash _((const char *));
uint_t elf_sys_encoding _((void));
long elf32_checksum _((Elf *));
diff --git a/usr/src/lib/libdtrace/common/dt_module.c b/usr/src/lib/libdtrace/common/dt_module.c
index 51a1bdd0d1..f8fdc4edbe 100644
--- a/usr/src/lib/libdtrace/common/dt_module.c
+++ b/usr/src/lib/libdtrace/common/dt_module.c
@@ -64,7 +64,7 @@ dt_module_symhash_insert(dt_module_t *dmp, const char *name, uint_t id)
static uint_t
dt_module_syminit32(dt_module_t *dmp)
{
-#if STT_NUM != (STT_IFUNC + 1)
+#if STT_NUM != (STT_TLS + 1)
#error "STT_NUM has grown. update dt_module_syminit32()"
#endif
@@ -78,7 +78,7 @@ dt_module_syminit32(dt_module_t *dmp)
const char *name = base + sym->st_name;
uchar_t type = ELF32_ST_TYPE(sym->st_info);
- if (type >= STT_IFUNC || type == STT_SECTION)
+ if (type >= STT_NUM || type == STT_SECTION)
continue; /* skip sections and unknown types */
if (sym->st_name == 0 || sym->st_name >= ss_size)
@@ -97,7 +97,7 @@ dt_module_syminit32(dt_module_t *dmp)
static uint_t
dt_module_syminit64(dt_module_t *dmp)
{
-#if STT_NUM != (STT_IFUNC + 1)
+#if STT_NUM != (STT_TLS + 1)
#error "STT_NUM has grown. update dt_module_syminit64()"
#endif
@@ -111,7 +111,7 @@ dt_module_syminit64(dt_module_t *dmp)
const char *name = base + sym->st_name;
uchar_t type = ELF64_ST_TYPE(sym->st_info);
- if (type >= STT_IFUNC || type == STT_SECTION)
+ if (type >= STT_NUM || type == STT_SECTION)
continue; /* skip sections and unknown types */
if (sym->st_name == 0 || sym->st_name >= ss_size)
@@ -474,7 +474,7 @@ dt_module_load_sect(dtrace_hdl_t *dtp, dt_module_t *dmp, ctf_sect_t *ctsp)
Elf_Data *dp;
Elf_Scn *sp;
- if (elf_getshstrndx(dmp->dm_elf, &shstrs) == 0)
+ if (elf_getshdrstrndx(dmp->dm_elf, &shstrs) == -1)
return (dt_set_errno(dtp, EDT_NOTLOADED));
for (sp = NULL; (sp = elf_nextscn(dmp->dm_elf, sp)) != NULL; ) {
@@ -823,7 +823,7 @@ dt_module_update(dtrace_hdl_t *dtp, const char *name)
(void) close(fd);
if (dmp->dm_elf == NULL || err == -1 ||
- elf_getshstrndx(dmp->dm_elf, &shstrs) == 0) {
+ elf_getshdrstrndx(dmp->dm_elf, &shstrs) == -1) {
dt_dprintf("failed to load %s: %s\n",
fname, elf_errmsg(elf_errno()));
dt_module_destroy(dtp, dmp);
diff --git a/usr/src/lib/libelfsign/common/elfsignlib.c b/usr/src/lib/libelfsign/common/elfsignlib.c
index d40a8bd0e9..361c83911d 100644
--- a/usr/src/lib/libelfsign/common/elfsignlib.c
+++ b/usr/src/lib/libelfsign/common/elfsignlib.c
@@ -20,12 +20,10 @@
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#define ELF_TARGET_ALL /* get definitions of all section flags */
#include <sys/types.h>
@@ -356,7 +354,7 @@ elfsign_begin(const char *filename, enum ES_ACTION action, ELFsign_t *essp)
* Call elf_getshstrndx to be sure we have a real ELF object
* this is required because elf_begin doesn't check that.
*/
- if (elf_getshstrndx(ess->es_elf, &ess->es_shstrndx) == 0) {
+ if (elf_getshdrstrndx(ess->es_elf, &ess->es_shstrndx) == -1) {
elfsign_end(ess);
cryptodebug("elfsign_begin: elf_getshstrndx failed");
return (ELFSIGN_INVALID_ELFOBJ);
diff --git a/usr/src/lib/libproc/common/Pcore.c b/usr/src/lib/libproc/common/Pcore.c
index 203408c5b9..2357be4364 100644
--- a/usr/src/lib/libproc/common/Pcore.c
+++ b/usr/src/lib/libproc/common/Pcore.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -1288,7 +1288,7 @@ core_find_text(struct ps_prochandle *P, Elf *elf, rd_loadobj_t *rlp)
uint_t i;
size_t nphdrs;
- if (elf_getphnum(elf, &nphdrs) == 0)
+ if (elf_getphdrnum(elf, &nphdrs) == -1)
return (NULL);
for (i = 0; i < nphdrs; i++) {
@@ -1323,7 +1323,7 @@ core_find_data(struct ps_prochandle *P, Elf *elf, rd_loadobj_t *rlp)
* as the virtual address at which is was loaded.
*/
if (gelf_getehdr(elf, &ehdr) == NULL ||
- elf_getphnum(elf, &nphdrs) == 0)
+ elf_getphdrnum(elf, &nphdrs) == -1)
return (NULL);
for (i = 0; i < nphdrs; i++) {
diff --git a/usr/src/lib/libproc/common/Pidle.c b/usr/src/lib/libproc/common/Pidle.c
index 5562385ef5..938510abeb 100644
--- a/usr/src/lib/libproc/common/Pidle.c
+++ b/usr/src/lib/libproc/common/Pidle.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -201,7 +201,7 @@ Pgrab_file(const char *fname, int *perr)
goto err;
}
- if (elf_getphnum(elf, &phnum) == 0) {
+ if (elf_getphdrnum(elf, &phnum) == -1) {
*perr = G_STRANGE;
goto err;
}
diff --git a/usr/src/lib/libproc/common/Psymtab.c b/usr/src/lib/libproc/common/Psymtab.c
index 7c05653eeb..725a765798 100644
--- a/usr/src/lib/libproc/common/Psymtab.c
+++ b/usr/src/lib/libproc/common/Psymtab.c
@@ -1664,8 +1664,8 @@ Pbuild_file_symtab(struct ps_prochandle *P, file_info_t *fptr)
if ((elf = fake_elf(P, fptr)) == NULL ||
elf_kind(elf) != ELF_K_ELF ||
gelf_getehdr(elf, &ehdr) == NULL ||
- elf_getshnum(elf, &nshdrs) == 0 ||
- elf_getshstrndx(elf, &shstrndx) == 0 ||
+ elf_getshdrnum(elf, &nshdrs) == -1 ||
+ elf_getshdrstrndx(elf, &shstrndx) == -1 ||
(scn = elf_getscn(elf, shstrndx)) == NULL ||
(shdata = elf_getdata(scn, NULL)) == NULL) {
dprintf("failed to fake up ELF file\n");
@@ -1675,8 +1675,8 @@ Pbuild_file_symtab(struct ps_prochandle *P, file_info_t *fptr)
} else if ((elf = elf_begin(fptr->file_fd, ELF_C_READ, NULL)) == NULL ||
elf_kind(elf) != ELF_K_ELF ||
gelf_getehdr(elf, &ehdr) == NULL ||
- elf_getshnum(elf, &nshdrs) == 0 ||
- elf_getshstrndx(elf, &shstrndx) == 0 ||
+ elf_getshdrnum(elf, &nshdrs) == -1 ||
+ elf_getshdrstrndx(elf, &shstrndx) == -1 ||
(scn = elf_getscn(elf, shstrndx)) == NULL ||
(shdata = elf_getdata(scn, NULL)) == NULL) {
int err = elf_errno();
@@ -1687,8 +1687,8 @@ Pbuild_file_symtab(struct ps_prochandle *P, file_info_t *fptr)
if ((elf = fake_elf(P, fptr)) == NULL ||
elf_kind(elf) != ELF_K_ELF ||
gelf_getehdr(elf, &ehdr) == NULL ||
- elf_getshnum(elf, &nshdrs) == 0 ||
- elf_getshstrndx(elf, &shstrndx) == 0 ||
+ elf_getshdrnum(elf, &nshdrs) == -1 ||
+ elf_getshdrstrndx(elf, &shstrndx) == -1 ||
(scn = elf_getscn(elf, shstrndx)) == NULL ||
(shdata = elf_getdata(scn, NULL)) == NULL) {
dprintf("failed to fake up ELF file\n");
@@ -1712,8 +1712,8 @@ Pbuild_file_symtab(struct ps_prochandle *P, file_info_t *fptr)
if ((newelf = fake_elf(P, fptr)) == NULL ||
elf_kind(newelf) != ELF_K_ELF ||
gelf_getehdr(newelf, &ehdr) == NULL ||
- elf_getshnum(newelf, &nshdrs) == 0 ||
- elf_getshstrndx(newelf, &shstrndx) == 0 ||
+ elf_getshdrnum(newelf, &nshdrs) == -1 ||
+ elf_getshdrstrndx(newelf, &shstrndx) == -1 ||
(scn = elf_getscn(newelf, shstrndx)) == NULL ||
(shdata = elf_getdata(scn, NULL)) == NULL) {
dprintf("failed to fake up ELF file\n");
@@ -2757,7 +2757,7 @@ static int
Psymbol_iter_com(struct ps_prochandle *P, Lmid_t lmid, const char *object_name,
int which, int mask, pr_order_t order, proc_xsym_f *func, void *cd)
{
-#if STT_NUM != (STT_IFUNC + 1)
+#if STT_NUM != (STT_TLS + 1)
#error "STT_NUM has grown. update Psymbol_iter_com()"
#endif
@@ -2845,7 +2845,7 @@ Psymbol_iter_com(struct ps_prochandle *P, Lmid_t lmid, const char *object_name,
* maintain binary compatibility, so I think this is
* reasonably fair game.
*/
- if (s_bind < STB_NUM && s_type < STT_IFUNC) {
+ if (s_bind < STB_NUM && s_type < STT_NUM) {
type = (1 << (s_type + 8)) | (1 << s_bind);
if ((type & ~mask) != 0)
continue;
diff --git a/usr/src/uts/common/sys/elf.h b/usr/src/uts/common/sys/elf.h
index a81bf5b2ed..0d4ce0babf 100644
--- a/usr/src/uts/common/sys/elf.h
+++ b/usr/src/uts/common/sys/elf.h
@@ -550,8 +550,7 @@ typedef struct {
#define STT_FILE 4 /* symbol's name is file name */
#define STT_COMMON 5 /* common data object */
#define STT_TLS 6 /* thread-local data object */
-#define STT_IFUNC 7 /* indirect code object (unused) */
-#define STT_NUM 8 /* # defined types in generic range */
+#define STT_NUM 7 /* # defined types in generic range */
#define STT_LOOS 10 /* OS specific range */
#define STT_HIOS 12
#define STT_LOPROC 13 /* processor specific range */