summaryrefslogtreecommitdiff
path: root/usr/src/cmd/sgs/libld
diff options
context:
space:
mode:
authorRichard Lowe <richlowe@richlowe.net>2019-02-11 18:22:00 +0000
committerRichard Lowe <richlowe@richlowe.net>2022-04-21 15:37:47 -0500
commitfb12490ab4d1e87e7a63e457dd4fba1ea34c402a (patch)
tree1117cd21bcded48dacf60a6ee71c96514b70b343 /usr/src/cmd/sgs/libld
parent7c8c0b8227679b4684566e408ccc96d6ef7175e9 (diff)
downloadillumos-gate-fb12490ab4d1e87e7a63e457dd4fba1ea34c402a.tar.gz
14090 ld(1) could use a normal allocator
Reviewed by: Gordon Ross <Gordon.W.Ross@gmail.com> Reviewed by: Jason King <jason.brian.king+illumos@gmail.com> Reviewed by: Michael van der Westhuizen <r1mikey@gmail.com> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/cmd/sgs/libld')
-rw-r--r--usr/src/cmd/sgs/libld/Makefile.com11
-rw-r--r--usr/src/cmd/sgs/libld/common/_libld.h25
-rw-r--r--usr/src/cmd/sgs/libld/common/files.c10
-rw-r--r--usr/src/cmd/sgs/libld/common/globals.c2
-rw-r--r--usr/src/cmd/sgs/libld/common/groups.c4
-rw-r--r--usr/src/cmd/sgs/libld/common/ldmain.c31
-rw-r--r--usr/src/cmd/sgs/libld/common/libld.msg1
-rw-r--r--usr/src/cmd/sgs/libld/common/libs.c6
-rw-r--r--usr/src/cmd/sgs/libld/common/machsym.sparc.c4
-rw-r--r--usr/src/cmd/sgs/libld/common/map.c3
-rw-r--r--usr/src/cmd/sgs/libld/common/map_core.c8
-rw-r--r--usr/src/cmd/sgs/libld/common/map_support.c10
-rw-r--r--usr/src/cmd/sgs/libld/common/outfile.c2
-rw-r--r--usr/src/cmd/sgs/libld/common/place.c10
-rw-r--r--usr/src/cmd/sgs/libld/common/sections.c12
-rw-r--r--usr/src/cmd/sgs/libld/common/sunwmove.c12
-rw-r--r--usr/src/cmd/sgs/libld/common/syms.c18
-rw-r--r--usr/src/cmd/sgs/libld/common/unwind.c4
-rw-r--r--usr/src/cmd/sgs/libld/common/util.c141
-rw-r--r--usr/src/cmd/sgs/libld/common/version.c18
20 files changed, 92 insertions, 240 deletions
diff --git a/usr/src/cmd/sgs/libld/Makefile.com b/usr/src/cmd/sgs/libld/Makefile.com
index f471b398bf..19c4f9caf2 100644
--- a/usr/src/cmd/sgs/libld/Makefile.com
+++ b/usr/src/cmd/sgs/libld/Makefile.com
@@ -113,8 +113,15 @@ LDLIBS += $(CONVLIBDIR) -lconv $(LDDBGLIBDIR) -llddbg \
DYNFLAGS += $(VERSREF) '-R$$ORIGIN'
# too hairy
-pics/sections32.o := SMATCH=off
-pics/sections64.o := SMATCH=off
+pics/sections32.o := SMATCH=off
+pics/sections64.o := SMATCH=off
+# confused about our strange allocation choices
+pics/syms32.o := SMOFF += check_kmalloc_wrong_size
+pics/syms64.o := SMOFF += check_kmalloc_wrong_size
+pics/entry32.o := SMOFF += check_kmalloc_wrong_size
+pics/entry64.o := SMOFF += check_kmalloc_wrong_size
+pics/relocate32.o := SMOFF += check_kmalloc_wrong_size
+pics/relocate64.o := SMOFF += check_kmalloc_wrong_size
BLTDEFS = msg.h
BLTDATA = msg.c
diff --git a/usr/src/cmd/sgs/libld/common/_libld.h b/usr/src/cmd/sgs/libld/common/_libld.h
index 42e15e4e82..7cbfe05e65 100644
--- a/usr/src/cmd/sgs/libld/common/_libld.h
+++ b/usr/src/cmd/sgs/libld/common/_libld.h
@@ -300,19 +300,6 @@ typedef struct sym_s_list {
} Sym_s_list;
/*
- * ld heap management structure
- */
-typedef struct _ld_heap Ld_heap;
-struct _ld_heap {
- Ld_heap *lh_next;
- void *lh_free;
- void *lh_end;
-};
-
-#define HEAPBLOCK 0x800000 /* default allocation block size */
-#define HEAPALIGN 0x8 /* heap blocks alignment requirement */
-
-/*
* Dynamic per-symbol filtee string table descriptor. This associates filtee
* strings that will be created in the .dynstr, with .dynamic entries.
*/
@@ -650,7 +637,6 @@ typedef struct {
extern char *Plibpath;
extern char *Llibdir;
extern char *Ulibdir;
-extern Ld_heap *ld_heap;
extern APlist *lib_support;
extern int demangle_flag;
extern const Msg reject[];
@@ -667,9 +653,14 @@ extern int cap_names_match(Alist *, Alist *);
extern void lds_atexit(Ofl_desc *, int);
-extern void libld_free(void *);
-extern void *libld_malloc(size_t);
-extern void *libld_realloc(void *, size_t);
+/*
+ * Note that libld has a long history of assuming that all allocations are
+ * 0-initialized. libld_malloc must maintain this.
+ */
+#define libld_free(x) free(x)
+#define libld_malloc(x) calloc(1, x)
+#define libld_realloc(x, s) realloc(x, s)
+#define libld_calloc(n, s) calloc(n, s)
extern int isdavl_compare(const void *, const void *);
diff --git a/usr/src/cmd/sgs/libld/common/files.c b/usr/src/cmd/sgs/libld/common/files.c
index 1fefa162cc..a3277b4bf1 100644
--- a/usr/src/cmd/sgs/libld/common/files.c
+++ b/usr/src/cmd/sgs/libld/common/files.c
@@ -188,7 +188,7 @@ process_section(const char *name, Ifl_desc *ifl, Shdr *shdr, Elf_Scn *scn,
* section elf_getdata() will still create a data buffer (the buffer
* will be null and the size will reflect the actual memory size).
*/
- if ((isp = libld_calloc(sizeof (Is_desc), 1)) == NULL)
+ if ((isp = libld_calloc(1, sizeof (Is_desc))) == NULL)
return (S_ERROR);
isp->is_shdr = shdr;
isp->is_file = ifl;
@@ -630,7 +630,7 @@ get_cap_group(Objcapset *ocapset, Word cnum, Ofl_desc *ofl, Is_desc *isp)
/*
* If a capabilities group is not found, create a new one.
*/
- if (((cgp = libld_calloc(sizeof (Cap_group), 1)) == NULL) ||
+ if (((cgp = libld_calloc(1, sizeof (Cap_group))) == NULL) ||
(aplist_append(&(ofl->ofl_capgroups), cgp,
AL_CNT_CAP_DESCS) == NULL))
return (NULL);
@@ -721,7 +721,7 @@ ld_cap_add_family(Ofl_desc *ofl, Sym_desc *lsdp, Sym_desc *csdp, Cap_group *cgp,
* Make sure the capability families have an initialized AVL tree.
*/
if ((avlt = ofl->ofl_capfamilies) == NULL) {
- if ((avlt = libld_calloc(sizeof (avl_tree_t), 1)) == NULL)
+ if ((avlt = libld_calloc(1, sizeof (avl_tree_t))) == NULL)
return (S_ERROR);
avl_create(avlt, &ld_sym_avl_comp, sizeof (Cap_avlnode),
SGSOFFSETOF(Cap_avlnode, cn_symavlnode.sav_node));
@@ -743,7 +743,7 @@ ld_cap_add_family(Ofl_desc *ofl, Sym_desc *lsdp, Sym_desc *csdp, Cap_group *cgp,
qcav.cn_symavlnode.sav_name = lsdp->sd_name;
if ((cav = avl_find(avlt, &qcav, &where)) == NULL) {
- if ((cav = libld_calloc(sizeof (Cap_avlnode), 1)) == NULL)
+ if ((cav = libld_calloc(1, sizeof (Cap_avlnode))) == NULL)
return (S_ERROR);
cav->cn_symavlnode.sav_hash = qcav.cn_symavlnode.sav_hash;
cav->cn_symavlnode.sav_name = qcav.cn_symavlnode.sav_name;
@@ -1033,7 +1033,7 @@ process_cap(Ofl_desc *ofl, Ifl_desc *ifl, Is_desc *cisp)
* is used, although it will be sparsely populated, as the list provides
* a convenient mechanism for traversal later.
*/
- if (((cdp = libld_calloc(sizeof (Cap_desc), 1)) == NULL) ||
+ if (((cdp = libld_calloc(1, sizeof (Cap_desc))) == NULL) ||
(aplist_append(&(cdp->ca_groups), NULL, cnum) == NULL))
return (S_ERROR);
diff --git a/usr/src/cmd/sgs/libld/common/globals.c b/usr/src/cmd/sgs/libld/common/globals.c
index eee3b9b8cb..71dda65bf2 100644
--- a/usr/src/cmd/sgs/libld/common/globals.c
+++ b/usr/src/cmd/sgs/libld/common/globals.c
@@ -33,8 +33,6 @@
#include "msg.h"
#include "_libld.h"
-Ld_heap *ld_heap; /* list of allocated blocks for */
- /* link-edit dynamic allocations */
APlist *lib_support; /* list of support libraries specified */
/* (-S option) */
int demangle_flag; /* symbol demangling required */
diff --git a/usr/src/cmd/sgs/libld/common/groups.c b/usr/src/cmd/sgs/libld/common/groups.c
index 2cca5da72d..75b5a6fb88 100644
--- a/usr/src/cmd/sgs/libld/common/groups.c
+++ b/usr/src/cmd/sgs/libld/common/groups.c
@@ -49,7 +49,7 @@ gpavl_loaded(Ofl_desc *ofl, Group_desc *gdp)
* Create a groups avl tree if required.
*/
if ((avlt = ofl->ofl_groups) == NULL) {
- if ((avlt = libld_calloc(sizeof (avl_tree_t), 1)) == NULL)
+ if ((avlt = libld_calloc(1, sizeof (avl_tree_t))) == NULL)
return (S_ERROR);
avl_create(avlt, isdavl_compare, sizeof (Isd_node),
SGSOFFSETOF(Isd_node, isd_avl));
@@ -73,7 +73,7 @@ gpavl_loaded(Ofl_desc *ofl, Group_desc *gdp)
/*
* This is a new group - so keep it.
*/
- if ((isdp = libld_calloc(sizeof (Isd_node), 1)) == NULL)
+ if ((isdp = libld_calloc(1, sizeof (Isd_node))) == NULL)
return (S_ERROR);
isdp->isd_name = isd.isd_name;
diff --git a/usr/src/cmd/sgs/libld/common/ldmain.c b/usr/src/cmd/sgs/libld/common/ldmain.c
index 650e2d63a8..080acccc8e 100644
--- a/usr/src/cmd/sgs/libld/common/ldmain.c
+++ b/usr/src/cmd/sgs/libld/common/ldmain.c
@@ -156,7 +156,7 @@ ld_main(int argc, char **argv, Half mach)
DBG_DELTATIME = DBG_TOTALTIME;
/* Output file descriptor */
- if ((ofl = libld_calloc(1, sizeof (Ofl_desc))) == 0)
+ if ((ofl = libld_calloc(1, sizeof (Ofl_desc))) == NULL)
return (1);
/* Initialize target state */
@@ -175,7 +175,7 @@ ld_main(int argc, char **argv, Half mach)
/*
* Build up linker version string
*/
- if ((ofl->ofl_sgsid = (char *)libld_calloc(MSG_SGS_ID_SIZE +
+ if ((ofl->ofl_sgsid = libld_calloc(MSG_SGS_ID_SIZE +
strlen(link_ver_string) + 1, 1)) == NULL)
return (1);
(void) strcpy(ofl->ofl_sgsid, MSG_ORIG(MSG_SGS_ID));
@@ -495,15 +495,14 @@ ld_main(int argc, char **argv, Half mach)
return (ld_exit(ofl));
/*
- * For performance reasons we don't actually free up the memory we've
- * allocated, it will be freed when we exit.
+ * For performance reasons we didn't used to actually free up the
+ * memory we'd allocated, since it'll be freed on exit.
*
- * But the below line can be uncommented if/when we want to measure how
- * our memory consumption and freeing are doing. We should be able to
- * free all the memory that has been allocated as part of the link-edit
- * process.
+ * These calls does not free nearly as much memory as you would think
+ * they do, unfortunately.
*/
- /* ld_ofl_cleanup(ofl); */
+ ld_ofl_cleanup(ofl);
+ libld_free(ofl);
return (0);
}
@@ -529,7 +528,6 @@ ifl_list_cleanup(APlist *apl)
void
ld_ofl_cleanup(Ofl_desc *ofl)
{
- Ld_heap *chp, *php;
Ar_desc *adp;
Aliste idx;
@@ -571,13 +569,8 @@ ld_ofl_cleanup(Ofl_desc *ofl)
(void) elf_end(ofl->ofl_elf);
(void) elf_end(ofl->ofl_welf);
- for (chp = ld_heap, php = NULL; chp; php = chp, chp = chp->lh_next) {
- if (php)
- (void) munmap((void *)php,
- (size_t)php->lh_end - (size_t)php);
- }
- if (php)
- (void) munmap((void *)php, (size_t)php->lh_end - (size_t)php);
-
- ld_heap = NULL;
+ /*
+ * Note that we don't free ofl itself here, just its contents. The
+ * ofl itself belongs to the caller.
+ */
}
diff --git a/usr/src/cmd/sgs/libld/common/libld.msg b/usr/src/cmd/sgs/libld/common/libld.msg
index 4184f8c1e3..8f61288f16 100644
--- a/usr/src/cmd/sgs/libld/common/libld.msg
+++ b/usr/src/cmd/sgs/libld/common/libld.msg
@@ -441,7 +441,6 @@
@ MSG_SYS_OPEN "file %s: open failed: %s"
@ MSG_SYS_UNLINK "file %s: unlink failed: %s"
-@ MSG_SYS_MMAPANON "mmap anon failed: %s"
@ MSG_SYS_MALLOC "malloc failed: %s"
diff --git a/usr/src/cmd/sgs/libld/common/libs.c b/usr/src/cmd/sgs/libld/common/libs.c
index f43b8f90d2..317646410b 100644
--- a/usr/src/cmd/sgs/libld/common/libs.c
+++ b/usr/src/cmd/sgs/libld/common/libs.c
@@ -216,7 +216,7 @@ ld_ar_setup(const char *name, Elf *elf, Ofl_desc *ofl)
adp->ad_start = start;
adp->ad_allextract = FALSE;
if (start) {
- adp->ad_aux = libld_calloc(sizeof (Ar_aux), number);
+ adp->ad_aux = libld_calloc(number, sizeof (Ar_aux));
if (adp->ad_aux == NULL)
return ((Ar_desc *)S_ERROR);
} else {
@@ -647,8 +647,8 @@ ar_extract_bysym(const char *name, int fd, Ar_desc *adp,
* allocate one.
*/
if (!amp) {
- if ((amp = libld_calloc(sizeof (Ar_mem),
- 1)) == NULL)
+ if ((amp = libld_calloc(1,
+ sizeof (Ar_mem))) == NULL)
return (FALSE);
amp->am_elf = arelf;
amp->am_name = arname;
diff --git a/usr/src/cmd/sgs/libld/common/machsym.sparc.c b/usr/src/cmd/sgs/libld/common/machsym.sparc.c
index 88b60c2158..db2005ef9c 100644
--- a/usr/src/cmd/sgs/libld/common/machsym.sparc.c
+++ b/usr/src/cmd/sgs/libld/common/machsym.sparc.c
@@ -236,8 +236,8 @@ ld_reg_enter_sparc(Sym_desc *sdp, Ofl_desc *ofl)
ofl->ofl_regsymsno = STO_SPARC_REGISTER_G7 + 1;
- if ((ofl->ofl_regsyms = libld_calloc(sizeof (Sym_desc *),
- ofl->ofl_regsymsno)) == NULL) {
+ if ((ofl->ofl_regsyms = libld_calloc(ofl->ofl_regsymsno,
+ sizeof (Sym_desc *))) == NULL) {
ofl->ofl_flags |= FLG_OF_FATAL;
return (0);
}
diff --git a/usr/src/cmd/sgs/libld/common/map.c b/usr/src/cmd/sgs/libld/common/map.c
index 401d66946f..e7711bb64d 100644
--- a/usr/src/cmd/sgs/libld/common/map.c
+++ b/usr/src/cmd/sgs/libld/common/map.c
@@ -1369,11 +1369,12 @@ ld_map_parse_v1(Mapfile *mf)
if (sgp1->sg_flags & FLG_SG_P_FLAGS)
stack->sg_phdr.p_flags =
sgp1->sg_phdr.p_flags;
- free(sgp1);
DBG_CALL(Dbg_map_seg(ofl,
DBG_STATE_MOD_AFTER, ndx, sgp1,
mf->mf_lineno));
+
+ free(sgp1);
break;
}
diff --git a/usr/src/cmd/sgs/libld/common/map_core.c b/usr/src/cmd/sgs/libld/common/map_core.c
index 5f2ad9a177..367e74c7bc 100644
--- a/usr/src/cmd/sgs/libld/common/map_core.c
+++ b/usr/src/cmd/sgs/libld/common/map_core.c
@@ -841,7 +841,7 @@ cexp_ident_add(Mapfile *mf, const char *name)
return (1);
}
- if ((node = libld_calloc(sizeof (*node), 1)) == NULL)
+ if ((node = libld_calloc(1, sizeof (*node))) == NULL)
return (0);
node->ceid_name = name;
avl_add(lms.lms_cexp_id, node);
@@ -893,7 +893,7 @@ cexp_ident_init(void)
if (lms.lms_cexp_id != NULL)
return (TRUE);
- lms.lms_cexp_id = libld_calloc(sizeof (*lms.lms_cexp_id), 1);
+ lms.lms_cexp_id = libld_calloc(1, sizeof (*lms.lms_cexp_id));
if (lms.lms_cexp_id == NULL)
return (FALSE);
avl_create(lms.lms_cexp_id, cexp_ident_cmp, sizeof (cexp_id_node_t),
@@ -1790,7 +1790,7 @@ gettoken_ident(Mapfile *mf, int flags, ld_map_tkval_t *tkv)
* mf_next pointer.
*/
tok = (*mf->mf_next & 0x80) ?
- TK_OP_ILLCHR : mf->mf_tokdisp[*mf->mf_next];
+ TK_OP_ILLCHR : mf->mf_tokdisp[(unsigned)*mf->mf_next];
switch (tok) {
case TK_OP_BADCHR:
null_patch_eol(mf->mf_next, &np);
@@ -2208,7 +2208,7 @@ mapfile_version(Mapfile *mf)
while (cont) {
/* Map the character to a dispatch action */
tok = (*mf->mf_next & 0x80) ?
- TK_OP_ILLCHR : gettok_dispatch_v2[*mf->mf_next];
+ TK_OP_ILLCHR : gettok_dispatch_v2[(unsigned)*mf->mf_next];
switch (tok) {
case TK_OP_WS: /* White space */
diff --git a/usr/src/cmd/sgs/libld/common/map_support.c b/usr/src/cmd/sgs/libld/common/map_support.c
index 722ba39f70..61d64b7fd9 100644
--- a/usr/src/cmd/sgs/libld/common/map_support.c
+++ b/usr/src/cmd/sgs/libld/common/map_support.c
@@ -169,11 +169,11 @@ ld_map_ifl(Mapfile *mf)
if (mf->mf_ifl != NULL)
return (mf->mf_ifl);
- if ((ifl = libld_calloc(sizeof (Ifl_desc), 1)) == NULL)
+ if ((ifl = libld_calloc(1, sizeof (Ifl_desc))) == NULL)
return (NULL);
ifl->ifl_name = mf->mf_name;
ifl->ifl_flags = (FLG_IF_MAPFILE | FLG_IF_NEEDED | FLG_IF_FILEREF);
- if ((ifl->ifl_ehdr = libld_calloc(sizeof (Ehdr), 1)) == NULL)
+ if ((ifl->ifl_ehdr = libld_calloc(1, sizeof (Ehdr))) == NULL)
return (NULL);
ifl->ifl_ehdr->e_type = ET_REL;
@@ -472,7 +472,7 @@ ld_map_seg_size_symbol(Mapfile *mf, Sg_desc *sgp, Token eq_tok,
if ((sdp = ld_sym_find(symname, SYM_NOHASH, &where, ofl)) == NULL) {
Word hval;
- if ((sym = libld_calloc(sizeof (Sym), 1)) == NULL)
+ if ((sym = libld_calloc(1, sizeof (Sym))) == NULL)
return (FALSE);
sym->st_shndx = SHN_ABS;
sym->st_size = 0;
@@ -532,7 +532,7 @@ ld_map_seg_alloc(const char *name, Word p_type, sg_flags_t sg_flags)
{
Sg_desc *sgp;
- if ((sgp = libld_calloc(sizeof (Sg_desc), 1)) == NULL)
+ if ((sgp = libld_calloc(1, sizeof (Sg_desc))) == NULL)
return (NULL);
sgp->sg_phdr.p_type = p_type;
sgp->sg_name = name;
@@ -1100,7 +1100,7 @@ ld_map_sym_enter(Mapfile *mf, ld_map_ver_t *mv, ld_map_sym_t *ms, Ass_desc *ma)
}
if ((sdp = ld_sym_find(ms->ms_name, hash, &where, ofl)) == NULL) {
- if ((sym = libld_calloc(sizeof (Sym), 1)) == NULL)
+ if ((sym = libld_calloc(1, sizeof (Sym))) == NULL)
return (FALSE);
sym->st_shndx = (Half)ms->ms_shndx;
diff --git a/usr/src/cmd/sgs/libld/common/outfile.c b/usr/src/cmd/sgs/libld/common/outfile.c
index 6d495fb33b..ba82886bb6 100644
--- a/usr/src/cmd/sgs/libld/common/outfile.c
+++ b/usr/src/cmd/sgs/libld/common/outfile.c
@@ -238,7 +238,7 @@ pad_outfile(Ofl_desc *ofl)
MSG_INTL(MSG_ELF_NEWDATA), ofl->ofl_name);
return (S_ERROR);
}
- if ((data->d_buf = libld_calloc(size, 1)) == 0)
+ if ((data->d_buf = libld_calloc(1, size)) == NULL)
return (S_ERROR);
data->d_type = ELF_T_BYTE;
diff --git a/usr/src/cmd/sgs/libld/common/place.c b/usr/src/cmd/sgs/libld/common/place.c
index ec1b688143..2724ab20a4 100644
--- a/usr/src/cmd/sgs/libld/common/place.c
+++ b/usr/src/cmd/sgs/libld/common/place.c
@@ -254,7 +254,7 @@ add_comdat(Ofl_desc *ofl, Os_desc *osp, Is_desc *isp)
* Create a COMDAT avl tree for this output section if required.
*/
if ((avlt = osp->os_comdats) == NULL) {
- if ((avlt = libld_calloc(sizeof (avl_tree_t), 1)) == NULL)
+ if ((avlt = libld_calloc(1, sizeof (avl_tree_t))) == NULL)
return (S_ERROR);
avl_create(avlt, isdavl_compare, sizeof (Isd_node),
SGSOFFSETOF(Isd_node, isd_avl));
@@ -295,7 +295,7 @@ add_comdat(Ofl_desc *ofl, Os_desc *osp, Is_desc *isp)
/*
* This is a new COMDAT section - so keep it.
*/
- if ((isdp = libld_calloc(sizeof (Isd_node), 1)) == NULL)
+ if ((isdp = libld_calloc(1, sizeof (Isd_node))) == NULL)
return (S_ERROR);
isdp->isd_name = isd.isd_name;
@@ -1080,7 +1080,7 @@ ld_place_section(Ofl_desc *ofl, Is_desc *isp, Place_path_info *path_info,
* - The ident values match
* - The names match
* - Not a GROUP section
- * - Not a DTrace dof section
+ * - Not a DTrace dof section
* - Section types match
* - Matching section flags, after screening out the
* shflagmask flags.
@@ -1214,9 +1214,9 @@ ld_place_section(Ofl_desc *ofl, Is_desc *isp, Place_path_info *path_info,
/*
* Create a new output section descriptor.
*/
- if ((osp = libld_calloc(sizeof (Os_desc), 1)) == NULL)
+ if ((osp = libld_calloc(1, sizeof (Os_desc))) == NULL)
return ((Os_desc *)S_ERROR);
- if ((osp->os_shdr = libld_calloc(sizeof (Shdr), 1)) == NULL)
+ if ((osp->os_shdr = libld_calloc(1, sizeof (Shdr))) == NULL)
return ((Os_desc *)S_ERROR);
/*
diff --git a/usr/src/cmd/sgs/libld/common/sections.c b/usr/src/cmd/sgs/libld/common/sections.c
index ec147c69b1..984c3c9b8e 100644
--- a/usr/src/cmd/sgs/libld/common/sections.c
+++ b/usr/src/cmd/sgs/libld/common/sections.c
@@ -636,7 +636,7 @@ new_section(Ofl_desc *ofl, Word shtype, const char *shname, Xword entcnt,
/*
* Allocate and initialize the Elf_Data structure.
*/
- if ((data = libld_calloc(sizeof (Elf_Data), 1)) == NULL)
+ if ((data = libld_calloc(1, sizeof (Elf_Data))) == NULL)
return (S_ERROR);
data->d_type = sec_info->d_type;
data->d_size = size;
@@ -646,7 +646,7 @@ new_section(Ofl_desc *ofl, Word shtype, const char *shname, Xword entcnt,
/*
* Allocate and initialize the Shdr structure.
*/
- if ((shdr = libld_calloc(sizeof (Shdr), 1)) == NULL)
+ if ((shdr = libld_calloc(1, sizeof (Shdr))) == NULL)
return (S_ERROR);
shdr->sh_type = shtype;
shdr->sh_size = size;
@@ -700,7 +700,7 @@ new_section_from_template(Ofl_desc *ofl, Is_desc *tmpl_isp, size_t size,
/*
* Allocate and initialize the Elf_Data structure.
*/
- if ((data = libld_calloc(sizeof (Elf_Data), 1)) == NULL)
+ if ((data = libld_calloc(1, sizeof (Elf_Data))) == NULL)
return (S_ERROR);
data->d_type = tmpl_isp->is_indata->d_type;
data->d_size = size;
@@ -842,7 +842,7 @@ make_array(Ofl_desc *ofl, Word shtype, const char *sectname, APlist *alp)
S_ERROR)
return (S_ERROR);
- if ((data->d_buf = libld_calloc(sizeof (Addr), entcount)) == NULL)
+ if ((data->d_buf = libld_calloc(entcount, sizeof (Addr))) == NULL)
return (S_ERROR);
if (ld_place_section(ofl, isec, NULL, ld_targ.t_id.id_array, NULL) ==
@@ -2198,7 +2198,7 @@ make_dynsort(Ofl_desc *ofl)
if (new_section(ofl, SHT_SUNW_symsort,
MSG_ORIG(MSG_SCN_DYNSYMSORT), ofl->ofl_dynsymsortcnt,
&isec, &shdr, &data) == S_ERROR)
- return (S_ERROR);
+ return (S_ERROR);
if ((ofl->ofl_osdynsymsort = ld_place_section(ofl, isec, NULL,
ld_targ.t_id.id_dynsort, NULL)) == (Os_desc *)S_ERROR)
@@ -2210,7 +2210,7 @@ make_dynsort(Ofl_desc *ofl)
if (new_section(ofl, SHT_SUNW_tlssort,
MSG_ORIG(MSG_SCN_DYNTLSSORT),
ofl->ofl_dyntlssortcnt, &isec, &shdr, &data) == S_ERROR)
- return (S_ERROR);
+ return (S_ERROR);
if ((ofl->ofl_osdyntlssort = ld_place_section(ofl, isec, NULL,
ld_targ.t_id.id_dynsort, NULL)) == (Os_desc *)S_ERROR)
diff --git a/usr/src/cmd/sgs/libld/common/sunwmove.c b/usr/src/cmd/sgs/libld/common/sunwmove.c
index f869802b08..c44250695b 100644
--- a/usr/src/cmd/sgs/libld/common/sunwmove.c
+++ b/usr/src/cmd/sgs/libld/common/sunwmove.c
@@ -37,7 +37,7 @@ make_mvsections(Ofl_desc *ofl)
{
Aliste idx;
Sym_desc *sdp;
- Word mv_nums = 0;
+ Word mv_nums = 0;
Xword align_parexpn = 0; /* for -z nopartial .data sec */
size_t size_parexpn = 0; /* size of parexpn section */
@@ -95,7 +95,7 @@ make_mvsections(Ofl_desc *ofl)
static uintptr_t
append_move_desc(Ofl_desc *ofl, Sym_desc *sdp, Move *mvp, Is_desc *isp)
{
- int i, cnt = mvp->m_repeat;
+ int i, cnt = mvp->m_repeat;
for (i = 0; i < cnt; i++) {
Aliste idx;
@@ -170,7 +170,7 @@ ld_process_move(Ofl_desc *ofl)
{
Aliste idx;
Is_desc *isp;
- int errcnt = 0;
+ int errcnt = 0;
for (APLIST_TRAVERSE(ofl->ofl_ismove, idx, isp)) {
Ifl_desc *ifile = isp->is_file;
@@ -190,7 +190,7 @@ ld_process_move(Ofl_desc *ofl)
num = isp->is_shdr->sh_size / isp->is_shdr->sh_entsize;
for (i = 0; i < num; i++) {
- Xword ndx = ELF_M_SYM(mvp->m_info);
+ Xword ndx = ELF_M_SYM(mvp->m_info);
Sym_desc *sdp;
Sym *sym;
@@ -288,8 +288,8 @@ ld_process_move(Ofl_desc *ofl)
if (sdp->sd_osym == NULL) {
if ((sdp->sd_osym =
- libld_calloc(sizeof (Sym),
- 1)) == NULL)
+ libld_calloc(1,
+ sizeof (Sym))) == NULL)
return (S_ERROR);
*(sdp->sd_osym) =
*(sdp->sd_sym);
diff --git a/usr/src/cmd/sgs/libld/common/syms.c b/usr/src/cmd/sgs/libld/common/syms.c
index 88f3ed7fa9..25ec329f4d 100644
--- a/usr/src/cmd/sgs/libld/common/syms.c
+++ b/usr/src/cmd/sgs/libld/common/syms.c
@@ -388,9 +388,9 @@ ld_sym_enter(const char *name, Sym *osym, Word hash, Ifl_desc *ifl,
* Allocate a Sym Descriptor, Auxiliary Descriptor, and a Sym AVLNode -
* contiguously.
*/
- if ((savl = libld_calloc(S_DROUND(sizeof (Sym_avlnode)) +
+ if ((savl = libld_calloc(1, S_DROUND(sizeof (Sym_avlnode)) +
S_DROUND(sizeof (Sym_desc)) +
- S_DROUND(sizeof (Sym_aux)), 1)) == NULL)
+ S_DROUND(sizeof (Sym_aux)))) == NULL)
return ((Sym_desc *)S_ERROR);
sdp = (Sym_desc *)((uintptr_t)savl +
S_DROUND(sizeof (Sym_avlnode)));
@@ -738,7 +738,7 @@ sym_add_spec(const char *name, const char *uname, Word sdaux_id,
/*
* If the symbol does not exist create it.
*/
- if ((sym = libld_calloc(sizeof (Sym), 1)) == NULL)
+ if ((sym = libld_calloc(1, sizeof (Sym))) == NULL)
return (S_ERROR);
sym->st_shndx = SHN_ABS;
sym->st_info = ELF_ST_INFO(STB_GLOBAL, STT_OBJECT);
@@ -2157,7 +2157,7 @@ ld_sym_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
return (S_ERROR);
if ((etype == ET_REL) && (local != 0)) {
if ((ifl->ifl_locs =
- libld_calloc(sizeof (Sym_desc), local)) == NULL)
+ libld_calloc(local, sizeof (Sym_desc))) == NULL)
return (S_ERROR);
/* LINTED */
ifl->ifl_locscnt = local;
@@ -2687,7 +2687,7 @@ ld_sym_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
(isp->is_flags & FLG_IS_DISCARD)) {
/* Discarded but not via COMDAT */
if ((sdp =
- libld_calloc(sizeof (Sym_desc), 1)) == NULL)
+ libld_calloc(1, sizeof (Sym_desc))) == NULL)
return (S_ERROR);
/*
@@ -3140,7 +3140,7 @@ ld_sym_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
idstr = capset->oc_id.cs_str;
nsize = strlen(oname);
tsize = nsize + 1 + strlen(idstr) + 1;
- if ((cname = libld_malloc(tsize)) == 0)
+ if ((cname = libld_malloc(tsize)) == NULL)
return (S_ERROR);
(void) strcpy(cname, oname);
@@ -3237,11 +3237,11 @@ ld_sym_add_u(const char *name, Ofl_desc *ofl, Msg mid)
* If no descriptor exists create one.
*/
if (ifl == NULL) {
- if ((ifl = libld_calloc(sizeof (Ifl_desc), 1)) == NULL)
+ if ((ifl = libld_calloc(1, sizeof (Ifl_desc))) == NULL)
return ((Sym_desc *)S_ERROR);
ifl->ifl_name = reference;
ifl->ifl_flags = FLG_IF_NEEDED | FLG_IF_FILEREF;
- if ((ifl->ifl_ehdr = libld_calloc(sizeof (Ehdr), 1)) == NULL)
+ if ((ifl->ifl_ehdr = libld_calloc(1, sizeof (Ehdr))) == NULL)
return ((Sym_desc *)S_ERROR);
ifl->ifl_ehdr->e_type = ET_REL;
@@ -3252,7 +3252,7 @@ ld_sym_add_u(const char *name, Ofl_desc *ofl, Msg mid)
/*
* Allocate a symbol structure and add it to the global symbol table.
*/
- if ((sym = libld_calloc(sizeof (Sym), 1)) == NULL)
+ if ((sym = libld_calloc(1, sizeof (Sym))) == NULL)
return ((Sym_desc *)S_ERROR);
sym->st_info = ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE);
sym->st_shndx = SHN_UNDEF;
diff --git a/usr/src/cmd/sgs/libld/common/unwind.c b/usr/src/cmd/sgs/libld/common/unwind.c
index f2960f74c6..bb773bc612 100644
--- a/usr/src/cmd/sgs/libld/common/unwind.c
+++ b/usr/src/cmd/sgs/libld/common/unwind.c
@@ -338,7 +338,7 @@ ld_unwind_make_hdr(Ofl_desc *ofl)
/*
* Allocate and initialize the Elf_Data structure.
*/
- if ((elfdata = libld_calloc(sizeof (Elf_Data), 1)) == NULL)
+ if ((elfdata = libld_calloc(1, sizeof (Elf_Data))) == NULL)
return (S_ERROR);
elfdata->d_type = ELF_T_BYTE;
elfdata->d_align = ld_targ.t_m.m_word_align;
@@ -347,7 +347,7 @@ ld_unwind_make_hdr(Ofl_desc *ofl)
/*
* Allocate and initialize the Shdr structure.
*/
- if ((shdr = libld_calloc(sizeof (Shdr), 1)) == NULL)
+ if ((shdr = libld_calloc(1, sizeof (Shdr))) == NULL)
return (S_ERROR);
shdr->sh_type = ld_targ.t_m.m_sht_unwind;
shdr->sh_flags = SHF_ALLOC;
diff --git a/usr/src/cmd/sgs/libld/common/util.c b/usr/src/cmd/sgs/libld/common/util.c
index 1da6589198..9595e8aaf9 100644
--- a/usr/src/cmd/sgs/libld/common/util.c
+++ b/usr/src/cmd/sgs/libld/common/util.c
@@ -50,143 +50,6 @@
#include "_libld.h"
/*
- * libld_malloc() and dz_map() are used for both performance and for ease of
- * programming:
- *
- * Performance:
- * The link-edit is a short lived process which doesn't really free much
- * of the dynamic memory that it requests. Because of this, it is more
- * important to optimize for quick memory allocations than the
- * re-usability of the memory.
- *
- * By also mmaping blocks of pages in from /dev/zero we don't need to
- * waste the overhead of zeroing out these pages for calloc() requests.
- *
- * Memory Management:
- * By doing all libld memory management through the ld_malloc routine
- * it's much easier to free up all memory at the end by simply unmaping
- * all of the blocks that were mapped in through dz_map(). This is much
- * simpler then trying to track all of the libld structures that were
- * dynamically allocate and are actually pointers into the ELF files.
- *
- * It's important that we can free up all of our dynamic memory because
- * libld is used by ld.so.1 when it performs dlopen()'s of relocatable
- * objects.
- *
- * Format:
- * The memory blocks for each allocation store the size of the allocation
- * in the first 8 bytes of the block. The pointer that is returned by
- * libld_malloc() is actually the address of (block + 8):
- *
- * (addr - 8) block_size
- * (addr) <allocated block>
- *
- * The size is retained in order to implement realloc(), and to perform
- * the required memcpy(). 8 bytes are uses, as the memory area returned
- * by libld_malloc() must be 8 byte-aligned. Even in a 32-bit environment,
- * u_longlog_t pointers are employed.
- *
- * Map anonymous memory via MAP_ANON (added in Solaris 8).
- */
-static void *
-dz_map(size_t size)
-{
- void *addr;
-
- if ((addr = mmap(0, size, (PROT_READ | PROT_WRITE | PROT_EXEC),
- (MAP_PRIVATE | MAP_ANON), -1, 0)) == MAP_FAILED) {
- int err = errno;
- eprintf(NULL, ERR_FATAL, MSG_INTL(MSG_SYS_MMAPANON),
- strerror(err));
- return (MAP_FAILED);
- }
- return (addr);
-}
-
-void *
-libld_malloc(size_t size)
-{
- Ld_heap *chp = ld_heap;
- void *vptr;
- size_t asize = size + HEAPALIGN;
-
- /*
- * If this is the first allocation, or the allocation request is greater
- * than the current free space available, allocate a new heap.
- */
- if ((chp == NULL) ||
- (((size_t)chp->lh_end - (size_t)chp->lh_free) <= asize)) {
- Ld_heap *nhp;
- size_t hsize = (size_t)S_ROUND(sizeof (Ld_heap), HEAPALIGN);
- size_t tsize = (size_t)S_ROUND((asize + hsize), HEAPALIGN);
-
- /*
- * Allocate a block that is at minimum 'HEAPBLOCK' size
- */
- if (tsize < HEAPBLOCK)
- tsize = HEAPBLOCK;
-
- if ((nhp = dz_map(tsize)) == MAP_FAILED)
- return (NULL);
-
- nhp->lh_next = chp;
- nhp->lh_free = (void *)((size_t)nhp + hsize);
- nhp->lh_end = (void *)((size_t)nhp + tsize);
-
- ld_heap = chp = nhp;
- }
- vptr = chp->lh_free;
-
- /*
- * Assign size to head of allocated block (used by realloc), and
- * memory arena as then next 8-byte aligned offset.
- */
- *((size_t *)vptr) = size;
- vptr = (void *)((size_t)vptr + HEAPALIGN);
-
- /*
- * Increment free to point to next available block
- */
- chp->lh_free = (void *)S_ROUND((size_t)chp->lh_free + asize,
- HEAPALIGN);
-
- return (vptr);
-}
-
-void *
-libld_realloc(void *ptr, size_t size)
-{
- size_t psize;
- void *vptr;
-
- if (ptr == NULL)
- return (libld_malloc(size));
-
- /*
- * Size of the allocated blocks is stored *just* before the blocks
- * address.
- */
- psize = *((size_t *)((size_t)ptr - HEAPALIGN));
-
- /*
- * If the block actually fits then just return.
- */
- if (size <= psize)
- return (ptr);
-
- if ((vptr = libld_malloc(size)) != NULL)
- (void) memcpy(vptr, ptr, psize);
-
- return (vptr);
-}
-
-void
-/* ARGSUSED 0 */
-libld_free(void *ptr)
-{
-}
-
-/*
* Determine if a shared object definition structure already exists and if
* not create one. These definitions provide for recording information
* regarding shared objects that are still to be processed. Once processed
@@ -230,7 +93,7 @@ sdf_add(const char *name, APlist **alpp)
{
Sdf_desc *sdf;
- if ((sdf = libld_calloc(sizeof (Sdf_desc), 1)) == NULL)
+ if ((sdf = libld_calloc(1, sizeof (Sdf_desc))) == NULL)
return ((Sdf_desc *)S_ERROR);
sdf->sdf_name = name;
@@ -756,7 +619,7 @@ cap_names_match(Alist *alp1, Alist *alp2)
for (ALIST_TRAVERSE(alp1, idx1, capstr1)) {
Capstr *capstr2;
- Aliste idx2;
+ Aliste idx2;
for (ALIST_TRAVERSE(alp2, idx2, capstr2)) {
if (strcmp(capstr1->cs_str, capstr2->cs_str))
diff --git a/usr/src/cmd/sgs/libld/common/version.c b/usr/src/cmd/sgs/libld/common/version.c
index 7f2ca139ef..b257fd8ade 100644
--- a/usr/src/cmd/sgs/libld/common/version.c
+++ b/usr/src/cmd/sgs/libld/common/version.c
@@ -58,7 +58,7 @@ ld_vers_desc(const char *name, Word hash, APlist **alpp)
{
Ver_desc *vdp;
- if ((vdp = libld_calloc(sizeof (Ver_desc), 1)) == NULL)
+ if ((vdp = libld_calloc(1, sizeof (Ver_desc))) == NULL)
return ((Ver_desc *)S_ERROR);
vdp->vd_name = name;
@@ -80,8 +80,8 @@ ld_vers_desc(const char *name, Word hash, APlist **alpp)
#define _NUM_OF_VERS_ 40 /* twice as big as the depth for libc version */
typedef struct {
Ver_desc **ver_stk;
- int ver_sp;
- int ver_lmt;
+ int ver_sp;
+ int ver_lmt;
} Ver_Stack;
static uintptr_t
@@ -146,7 +146,7 @@ vers_visit_children(Ofl_desc *ofl, Ver_desc *vp, int flag)
if (ver_stk.ver_sp >= ver_stk.ver_lmt) {
ver_stk.ver_lmt += _NUM_OF_VERS_;
if ((ver_stk.ver_stk = (Ver_desc **)
- libld_realloc((void *)ver_stk.ver_stk,
+ libld_realloc(ver_stk.ver_stk,
ver_stk.ver_lmt * sizeof (Ver_desc *))) == NULL)
return (S_ERROR);
}
@@ -172,7 +172,7 @@ ld_vers_check_defs(Ofl_desc *ofl)
{
Aliste idx1;
Ver_desc *vdp;
- uintptr_t is_cyclic = 0;
+ uintptr_t is_cyclic = 0;
DBG_CALL(Dbg_ver_def_title(ofl->ofl_lml, ofl->ofl_name));
@@ -281,7 +281,7 @@ ld_vers_check_defs(Ofl_desc *ofl)
/*
* If the symbol does not exist create it.
*/
- if ((sym = libld_calloc(sizeof (Sym), 1)) == NULL)
+ if ((sym = libld_calloc(1, sizeof (Sym))) == NULL)
return (S_ERROR);
sym->st_shndx = SHN_ABS;
@@ -487,7 +487,7 @@ vers_index(Ofl_desc *ofl, Ifl_desc *ifl, int avail)
* Allocate an index array large enough to hold all of the files
* version descriptors.
*/
- if ((vip = libld_calloc(sizeof (Ver_index), (count + 1))) == NULL)
+ if ((vip = libld_calloc((count + 1), sizeof (Ver_index))) == NULL)
return ((Ver_index *)S_ERROR);
for (APLIST_TRAVERSE(ifl->ifl_verdesc, idx1, vdp)) {
@@ -648,7 +648,7 @@ ld_vers_def_process(Is_desc *isp, Ifl_desc *ifl, Ofl_desc *ofl)
const char *name;
Ver_desc *ivdp, *ovdp = NULL;
Word hash;
- Half cnt = vdf->vd_cnt;
+ Half cnt = vdf->vd_cnt;
Half ndx = vdf->vd_ndx;
Verdaux *vdap = (Verdaux *)((uintptr_t)vdf +
vdf->vd_aux);
@@ -893,7 +893,7 @@ ld_vers_need_process(Is_desc *isp, Ifl_desc *ifl, Ofl_desc *ofl)
void
ld_vers_promote(Sym_desc *sdp, Word ndx, Ifl_desc *ifl, Ofl_desc *ofl)
{
- Half vndx;
+ Half vndx;
/*
* A version symbol index of 0 implies the symbol is local. A value of