Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/gnu/usr.bin/ld/ld More alloca() -> malloc(). Needed to make...
details: https://anonhg.NetBSD.org/src/rev/a6c8d2beb2f4
branches: trunk
changeset: 480442:a6c8d2beb2f4
user: mycroft <mycroft%NetBSD.org@localhost>
date: Thu Jan 13 00:05:32 2000 +0000
description:
More alloca() -> malloc(). Needed to make some shared libraries link when
compiled with -g.
diffstat:
gnu/usr.bin/ld/ld/ld.c | 28 ++++++++++++++++++----------
gnu/usr.bin/ld/ld/lib.c | 27 +++++++++++++++++++--------
gnu/usr.bin/ld/ld/rrs.c | 9 ++++++---
3 files changed, 43 insertions(+), 21 deletions(-)
diffs (240 lines):
diff -r a79ba2f91cfd -r a6c8d2beb2f4 gnu/usr.bin/ld/ld/ld.c
--- a/gnu/usr.bin/ld/ld/ld.c Thu Jan 13 00:04:31 2000 +0000
+++ b/gnu/usr.bin/ld/ld/ld.c Thu Jan 13 00:05:32 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ld.c,v 1.67 1999/12/01 03:45:54 phil Exp $ */
+/* $NetBSD: ld.c,v 1.68 2000/01/13 00:05:32 mycroft Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -88,7 +88,7 @@
#ifndef lint
/* from: "@(#)ld.c 6.10 (Berkeley) 5/22/91"; */
-__RCSID("$NetBSD: ld.c,v 1.67 1999/12/01 03:45:54 phil Exp $");
+__RCSID("$NetBSD: ld.c,v 1.68 2000/01/13 00:05:32 mycroft Exp $");
#endif /* not lint */
#define GNU_BINUTIL_COMPAT /* forwards compatiblity with binutils 2.x */
@@ -1334,7 +1334,7 @@
if (!(entry->flags & E_HEADER_VALID))
read_header(fd, entry);
- np = (struct nlist *)alloca(entry->header.a_syms);
+ np = (struct nlist *)malloc(entry->header.a_syms);
entry->nsymbols = entry->header.a_syms / sizeof(struct nlist);
if (entry->nsymbols == 0)
return;
@@ -1353,7 +1353,7 @@
md_swapin_symbols(np, entry->header.a_syms / sizeof(struct nlist));
for (i = 0; i < entry->nsymbols; i++) {
- entry->symbols[i].nzlist.nlist = *np++;
+ entry->symbols[i].nzlist.nlist = np[i];
entry->symbols[i].nzlist.nz_size = 0;
entry->symbols[i].symbol = NULL;
entry->symbols[i].next = NULL;
@@ -1361,6 +1361,7 @@
entry->symbols[i].gotslot_offset = -1;
entry->symbols[i].flags = 0;
}
+ free(np);
entry->strings_offset = N_STROFF(entry->header) +
entry->starting_offset;
@@ -1525,10 +1526,11 @@
if (N_GETFLAG(hdr) & EX_PIC)
pic_code_seen = 1;
read_entry_symbols(fd, entry);
- entry->strings = (char *)alloca(entry->string_size);
+ entry->strings = (char *)malloc(entry->string_size);
read_entry_strings(fd, entry);
read_entry_relocation(fd, entry);
enter_file_symbols(entry);
+ free(entry->strings);
entry->strings = 0;
}
} else {
@@ -2995,7 +2997,7 @@
fd = file_open(entry);
/* Allocate space for the file's text section */
- bytes = (char *)alloca(entry->header.a_text);
+ bytes = (char *)malloc(entry->header.a_text);
/* Deal with relocation information however is appropriate */
if (entry->textrel == NULL)
@@ -3013,6 +3015,8 @@
/* Write the relocated text to the output file. */
mywrite(bytes, entry->header.a_text, 1, outstream);
+
+ free(bytes);
}
/*
@@ -3069,7 +3073,7 @@
fd = file_open(entry);
- bytes = (char *)alloca(entry->header.a_data);
+ bytes = (char *)malloc(entry->header.a_data);
if (entry->datarel == NULL)
errx(1, "%s: no data relocation", get_file_name(entry));
@@ -3084,6 +3088,8 @@
entry->datarel, entry->ndatarel, entry, 1);
mywrite(bytes, entry->header.a_data, 1, outstream);
+
+ free(bytes);
}
/*
@@ -3966,7 +3972,7 @@
}
/* Read the file's string table. */
- entry->strings = (char *)alloca(entry->string_size);
+ entry->strings = (char *)malloc(entry->string_size);
read_entry_strings(file_open(entry), entry);
lspend = entry->symbols + entry->nsymbols;
@@ -4016,8 +4022,9 @@
* Write the string-table data for the symbols just written, using
* the data in vectors `strtab_vector' and `strtab_lens'.
*/
-
write_string_table();
+
+ free(entry->strings);
entry->strings = 0; /* Since it will disappear anyway. */
}
@@ -4082,7 +4089,8 @@
if (padding <= 0)
return;
- buf = (char *)alloca(padding);
+ buf = (char *)malloc(padding);
bzero(buf, padding);
mywrite(buf, padding, 1, fd);
+ free(buf);
}
diff -r a79ba2f91cfd -r a6c8d2beb2f4 gnu/usr.bin/ld/ld/lib.c
--- a/gnu/usr.bin/ld/ld/lib.c Thu Jan 13 00:04:31 2000 +0000
+++ b/gnu/usr.bin/ld/ld/lib.c Thu Jan 13 00:05:32 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.c,v 1.21 1999/12/01 03:45:54 phil Exp $ */
+/* $NetBSD: lib.c,v 1.22 2000/01/13 00:05:32 mycroft Exp $ */
/*
* - library routines
@@ -391,7 +391,7 @@
return;
read_entry_symbols(fd, subentry);
- subentry->strings = (char *)alloca(subentry->string_size);
+ subentry->strings = (char *)malloc(subentry->string_size);
read_entry_strings(fd, subentry);
if (!(link_mode & FORCEARCHIVE) &&
@@ -399,6 +399,7 @@
if (subentry->symbols)
free(subentry->symbols);
free(subentry->filename);
+ free(subentry->strings);
free(subentry);
} else {
read_entry_relocation(fd, subentry);
@@ -409,6 +410,7 @@
else
entry->subfiles = subentry;
prev = subentry;
+ free(subentry->strings);
subentry->strings = 0; /* Since space will dissapear
* on return */
}
@@ -645,9 +647,13 @@
/* Read symbols (text segment) */
n = sdt.sdt_strings - sdt.sdt_nzlist;
- entry->nsymbols = n /
- (has_nz ? sizeof(struct nzlist) : sizeof(struct nlist));
- nzp = (struct nzlist *)(np = (struct nlist *)alloca (n));
+ if (has_nz) {
+ entry->nsymbols = n / sizeof(struct nzlist);
+ nzp = (struct nzlist *)malloc(n);
+ } else {
+ entry->nsymbols = n / sizeof(struct nlist);
+ np = (struct nlist *)malloc(n);
+ }
entry->symbols = (struct localsymbol *)
xmalloc(entry->nsymbols * sizeof(struct localsymbol));
@@ -668,9 +674,9 @@
/* Convert to structs localsymbol */
for (i = 0; i < entry->nsymbols; i++) {
if (has_nz) {
- entry->symbols[i].nzlist = *nzp++;
+ entry->symbols[i].nzlist = nzp[i];
} else {
- entry->symbols[i].nzlist.nlist = *np++;
+ entry->symbols[i].nzlist.nlist = np[i];
entry->symbols[i].nzlist.nz_size = 0;
}
entry->symbols[i].symbol = NULL;
@@ -679,10 +685,14 @@
entry->symbols[i].gotslot_offset = -1;
entry->symbols[i].flags = 0;
}
+ if (has_nz)
+ free(nzp);
+ else
+ free(np);
/* Read strings (text segment) */
n = entry->string_size = sdt.sdt_str_sz;
- entry->strings = (char *)alloca(n);
+ entry->strings = (char *)malloc(n);
entry->strings_offset = text_offset(entry) + sdt.sdt_strings;
if (lseek(fd,
entry->strings_offset -
@@ -693,6 +703,7 @@
errx(1, "%s: premature EOF reading strings",
get_file_name(entry));
enter_file_symbols (entry);
+ free(entry->strings);
entry->strings = 0;
/*
diff -r a79ba2f91cfd -r a6c8d2beb2f4 gnu/usr.bin/ld/ld/rrs.c
--- a/gnu/usr.bin/ld/ld/rrs.c Thu Jan 13 00:04:31 2000 +0000
+++ b/gnu/usr.bin/ld/ld/rrs.c Thu Jan 13 00:05:32 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rrs.c,v 1.31 2000/01/07 21:19:36 mycroft Exp $ */
+/* $NetBSD: rrs.c,v 1.32 2000/01/13 00:05:32 mycroft Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -1016,8 +1016,8 @@
* to collect them in.
*/
symsize = number_of_rrs_symbols * rrs_symbol_size;
- nlp = rrs_symbols = (struct nzlist *)alloca(symsize);
- rrs_strtab = (char *)alloca(rrs_strtab_size);
+ nlp = rrs_symbols = (struct nzlist *)malloc(symsize);
+ rrs_strtab = (char *)malloc(rrs_strtab_size);
#define INCR_NLP(p) ((p) = (struct nzlist *)((long)(p) + rrs_symbol_size))
@@ -1229,6 +1229,9 @@
mywrite(name, strlen(name) + 1, 1, outstream);
}
+
+ free(rrs_symbols);
+ free(rrs_strtab);
}
void
Home |
Main Index |
Thread Index |
Old Index