diff options
| author | pk <pk@NetBSD.org> | 1998-12-17 14:34:51 +0000 |
|---|---|---|
| committer | pk <pk@NetBSD.org> | 1998-12-17 14:34:51 +0000 |
| commit | e9e87c8beebca1f5bba0f3824beda2e8b849d648 (patch) | |
| tree | 04d0be9c11c3091d1c236bf3eb990f02edf71ebb /gnu/usr.bin/ld | |
| parent | 76ae27e1f847ded1060b7ae4b7446412039b582c (diff) | |
Collect implementation definitions in `ld_i.h' and use that in other files.
Deal with missing and incorrect prototypes, so this compiles with gcc's
strict error checking turned on.
Diffstat (limited to 'gnu/usr.bin/ld')
| -rw-r--r-- | gnu/usr.bin/ld/ld/Makefile | 4 | ||||
| -rw-r--r-- | gnu/usr.bin/ld/ld/ld.c | 307 | ||||
| -rw-r--r-- | gnu/usr.bin/ld/ld/ld_i.h | 444 | ||||
| -rw-r--r-- | gnu/usr.bin/ld/ld/lib.c | 82 | ||||
| -rw-r--r-- | gnu/usr.bin/ld/ld/rrs.c | 32 | ||||
| -rw-r--r-- | gnu/usr.bin/ld/ld/symbol.c | 7 | ||||
| -rw-r--r-- | gnu/usr.bin/ld/ld/warnings.c | 40 | ||||
| -rw-r--r-- | gnu/usr.bin/ld/ld/xbits.c | 48 |
8 files changed, 831 insertions, 133 deletions
diff --git a/gnu/usr.bin/ld/ld/Makefile b/gnu/usr.bin/ld/ld/Makefile index 7c5d5e068b8..3e2611625c9 100644 --- a/gnu/usr.bin/ld/ld/Makefile +++ b/gnu/usr.bin/ld/ld/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.4 1998/08/13 07:34:05 mycroft Exp $ +# $NetBSD: Makefile,v 1.5 1998/12/17 14:34:51 pk Exp $ .if (${MACHINE_ARCH} == "i386") || \ (${MACHINE_ARCH} == "m68k") || \ @@ -7,7 +7,7 @@ (${MACHINE_ARCH} == "vax") || \ (${MACHINE_ARCH} == "arm32") PROG= ld -SRCS= ld.c symbol.c lib.c shlib.c warnings.c etc.c rrs.c xbits.c md.c +SRCS= ld.c symbol.c lib.c shlib.c warnings.c rrs.c xbits.c md.c .if defined(DEBUG) CPPFLAGS+=-DDEBUG .endif diff --git a/gnu/usr.bin/ld/ld/ld.c b/gnu/usr.bin/ld/ld/ld.c index 42880b5e3aa..1218619edd3 100644 --- a/gnu/usr.bin/ld/ld/ld.c +++ b/gnu/usr.bin/ld/ld/ld.c @@ -1,4 +1,39 @@ -/* $NetBSD: ld.c,v 1.61 1998/12/15 22:34:38 pk Exp $ */ +/* $NetBSD: ld.c,v 1.62 1998/12/17 14:34:51 pk Exp $ */ +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Paul Kranenburg. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ /*- * This code is derived from software copyrighted by the Free Software @@ -9,9 +44,6 @@ * Modified 1993 by Paul Kranenburg, Erasmus University */ -#ifndef lint -static char sccsid[] = "@(#)ld.c 6.10 (Berkeley) 5/22/91"; -#endif /* not lint */ /* Linker `ld' for GNU Copyright (C) 1988 Free Software Foundation, Inc. @@ -37,10 +69,10 @@ static char sccsid[] = "@(#)ld.c 6.10 (Berkeley) 5/22/91"; #include <sys/param.h> #include <sys/types.h> +#include <sys/cdefs.h> #include <sys/stat.h> #include <sys/file.h> #include <sys/time.h> -#include <sys/resource.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -53,13 +85,200 @@ static char sccsid[] = "@(#)ld.c 6.10 (Berkeley) 5/22/91"; #include <stab.h> #include <string.h> +#ifndef lint +/* from: "@(#)ld.c 6.10 (Berkeley) 5/22/91"; */ +__RCSID("$NetBSD: ld.c,v 1.62 1998/12/17 14:34:51 pk Exp $"); +#endif /* not lint */ + #define GNU_BINUTIL_COMPAT /* forwards compatiblity with binutils 2.x */ /*#define DEBUG_COMPAT*/ +#include "shlib.h" #include "ld.h" +#include "ld_i.h" + +/* + * Symbol types understood and processed by this linker which do + * not appear in the original <a.out> format. + * + * N_WARN + * If a this type of symbol is encountered, its name is a warning + * message to print each time the symbol referenced by the next symbol + * table entry is referenced. + * + * This feature may be used to allow backwards compatibility with + * certain functions (eg. gets) but to discourage programmers from + * their use. + * + * So if, for example, you wanted to have ld print a warning whenever + * the function "gets" was used in their C program, you would add the + * following to the assembler file in which gets is defined: + * + * .stabs "Obsolete function \"gets\" referenced",30,0,0,0 + * .stabs "_gets",1,0,0,0 + * + * These .stabs do not necessarily have to be in the same file as the + * gets function, they simply must exist somewhere in the compilation. + * + * + * N_INDR + * Indicates the definition of a symbol as being an indirect reference + * to another symbol. The other symbol appears as an undefined + * reference, immediately following this symbol. + * + * Indirection is asymmetrical. The other symbol's value will be used + * to satisfy requests for the indirect symbol, but not vice versa. + * If the other symbol does not have a definition, libraries will + * be searched to find a definition. + * + * So, for example, the following two lines placed in an assembler + * input file would result in an object file which would direct gnu ld + * to resolve all references to symbol "foo" as references to symbol + * "bar". + * + * .stabs "_foo",11,0,0,0 + * .stabs "_bar",1,0,0,0 + * + * Note that (11 == (N_INDR | N_EXT)) and (1 == (N_UNDF | N_EXT)). + * + * + * N_SETA + * N_SETT + * N_SETD + * N_SETB + * N_SETV + * These symbols refer to set elements. These are expected only + * in input to the loader; they should not appear in loader output + * (unless relocatable output is requested). To be recognized by + * the loader, the input symbols must have their N_EXT bit set. + * All the N_SET[ATDB] symbols with the same name form one set. The + * loader collects all of these elements at load time and outputs a + * vector for each name. + * Space (an array of 32 bit words) is allocated for the set in the + * data section, and the n_value field of each set element value is + * stored into one word of the array. + * The first word of the array is the length of the set (number of + * elements). The last word of the vector is set to zero for possible + * use by incremental loaders. The array is ordered by the linkage + * order; the first symbols which the linker encounters will be first + * in the array. + * + * In C syntax this looks like: + * + * struct set_vector { + * unsigned int length; + * unsigned int vector[length]; + * unsigned int always_zero; + * }; + * + * Before being placed into the array, each element is relocated + * according to its type. This allows the loader to create an array + * of pointers to objects automatically. N_SETA type symbols will not + * be relocated. + * + * The address of the set is made into an N_SETV symbol whose name is + * the same as the name of the set. This symbol acts like a N_DATA global + * symbol in that it can satisfy undefined external references. + * + * For the purposes of determining whether or not to load in a library + * file, set element definitions are not considered "real + * definitions"; they will not cause the loading of a library + * member. + * + * If relocatable output is requested, none of this processing is + * done. The symbols are simply relocated and passed through to the + * output file. + * + * So, for example, the following three lines of assembler code + * (whether in one file or scattered between several different ones) + * will produce a three element vector (total length is five words; + * see above), referenced by the symbol "_xyzzy", which will have the + * addresses of the routines _init1, _init2, and _init3. + * + * *NOTE*: If symbolic addresses are used in the n_value field of the + * defining .stabs, those symbols must be defined in the same file as + * that containing the .stabs. + * + * .stabs "_xyzzy",23,0,0,_init1 + * .stabs "_xyzzy",23,0,0,_init2 + * .stabs "_xyzzy",23,0,0,_init3 + * + * Note that (23 == (N_SETT | N_EXT)). + * + */ -/* Vector of entries for input files specified by arguments. - These are all the input files except for members of specified libraries. */ +/* + * Ok. Following are the relocation information macros. If your + * system should not be able to use the default set (below), you must + * define the following (in <arch/---/md.h>: + + * relocation_info: This must be typedef'd (or #define'd) to the type + * of structure that is stored in the relocation info section of your + * a.out files. Often this is defined in the a.out.h for your system. + * + * RELOC_ADDRESS (rval): Offset into the current section of the + * <whatever> to be relocated. *Must be an lvalue*. + * + * RELOC_EXTERN_P (rval): Is this relocation entry based on an + * external symbol (1), or was it fully resolved upon entering the + * loader (0) in which case some combination of the value in memory + * (if RELOC_MEMORY_ADD_P) and the extra (if RELOC_ADD_EXTRA) contains + * what the value of the relocation actually was. *Must be an lvalue*. + * + * RELOC_TYPE (rval): If this entry was fully resolved upon + * entering the loader, what type should it be relocated as? + * + * RELOC_SYMBOL (rval): If this entry was not fully resolved upon + * entering the loader, what is the index of it's symbol in the symbol + * table? *Must be a lvalue*. + * + * RELOC_MEMORY_ADD_P (rval): This should return true if the final + * relocation value output here should be added to memory, or if the + * section of memory described should simply be set to the relocation + * value. + * + * RELOC_ADD_EXTRA (rval): (Optional) This macro, if defined, gives + * an extra value to be added to the relocation value based on the + * individual relocation entry. *Must be an lvalue if defined*. + * + * RELOC_PCREL_P (rval): True if the relocation value described is + * pc relative. + * + * RELOC_VALUE_RIGHTSHIFT (rval): Number of bits right to shift the + * final relocation value before putting it where it belongs. + * + * RELOC_TARGET_SIZE (rval): log to the base 2 of the number of + * bytes of size this relocation entry describes; 1 byte == 0; 2 bytes + * == 1; 4 bytes == 2, and etc. This is somewhat redundant (we could + * do everything in terms of the bit operators below), but having this + * macro could end up producing better code on machines without fancy + * bit twiddling. Also, it's easier to understand/code big/little + * endian distinctions with this macro. + * + * RELOC_TARGET_BITPOS (rval): The starting bit position within the + * object described in RELOC_TARGET_SIZE in which the relocation value + * will go. + * + * RELOC_TARGET_BITSIZE (rval): How many bits are to be replaced + * with the bits of the relocation value. It may be assumed by the + * code that the relocation value will fit into this many bits. This + * may be larger than RELOC_TARGET_SIZE if such be useful. + * + * + * Things I haven't implemented + * ---------------------------- + * + * Values for RELOC_TARGET_SIZE other than 0, 1, or 2. + * + * Pc relative relocation for External references. + * + * + */ + +/* + * Vector of entries for input files specified by arguments. + * These are all the input files except for members of specified libraries. + */ struct file_entry *file_table; int number_of_files; @@ -261,6 +480,7 @@ static void consider_local_symbols __P((struct file_entry *)); static void perform_relocation __P((char *, int, struct relocation_info *, int, struct file_entry *, int)); +unsigned long contains_symbol __P((struct file_entry *, struct nlist *)); static void copy_text __P((struct file_entry *)); static void copy_data __P((struct file_entry *)); static void coptxtrel __P((struct file_entry *)); @@ -272,8 +492,12 @@ static void write_data __P((void)); static void write_rel __P((void)); static void write_syms __P((void)); static void assign_symbolnums __P((struct file_entry *, int *)); +static int assign_string_table_index __P((char *)); static void cleanup __P((void)); +static void file_close __P((void)); static int parse __P((char *, char *, char *)); +static void add_cmdline_ref __P((symbol *)); +int main __P((int, char *[])); int @@ -877,10 +1101,10 @@ do_rpath: void each_file(function, arg) - register void (*function)(); - register void *arg; + void (*function) __P((struct file_entry *, void *)); + void *arg; { - register int i; + int i; for (i = 0; i < number_of_files; i++) { register struct file_entry *entry = &file_table[i]; @@ -930,11 +1154,11 @@ each_file(function, arg) unsigned long check_each_file(function, arg) - register unsigned long (*function)(); - register void *arg; + unsigned long (*function) __P((struct file_entry *, void *)); + void *arg; { - register int i; - register unsigned long return_val; + int i; + unsigned long ret; for (i = 0; i < number_of_files; i++) { register struct file_entry *entry = &file_table[i]; @@ -945,23 +1169,23 @@ check_each_file(function, arg) for (; subentry; subentry = subentry->chain) { if (subentry->flags & E_SCRAPPED) continue; - if (return_val = (*function)(subentry, arg)) - return return_val; + if ((ret = (*function)(subentry, arg)) != 0) + return (ret); } - } else if (return_val = (*function)(entry, arg)) - return return_val; + } else if ((ret = (*function)(entry, arg)) != 0) + return (ret); } - return 0; + return (0); } /* Like `each_file' but ignore files that were just for symbol definitions. */ void each_full_file(function, arg) - register void (*function)(); - register void *arg; + void (*function) __P((struct file_entry *, void *)); + void *arg; { - register int i; + int i; for (i = 0; i < number_of_files; i++) { register struct file_entry *entry = &file_table[i]; @@ -1003,8 +1227,9 @@ each_full_file(function, arg) } } -/* Close the input file that is now open. */ - +/* + * Close the input file that is now open. + */ void file_close() { @@ -1356,7 +1581,7 @@ enter_file_symbols(entry) if (!relocatable_output) enter_global_ref(lsp, p->n_un.n_strx + entry->strings, entry); - } else if (p->n_type == N_WARNING) { + } else if (p->n_type == N_WARN) { char *msg = p->n_un.n_strx + entry->strings; /* Grab the next entry. */ @@ -1372,7 +1597,7 @@ enter_file_symbols(entry) symbol *sp; char *name = p->n_un.n_strx + entry->strings; /* Deal with the warning symbol. */ - lsp->flags |= LS_WARNING; + lsp->flags |= LS_WARN; enter_global_ref(lsp, name, entry); sp = getsym(name); if (sp->warning == NULL) { @@ -1481,7 +1706,7 @@ enter_global_ref(lsp, name, entry) if (nzp->nz_size > sp->size) sp->size = nzp->nz_size; - if ((lsp->flags & LS_WARNING) && (sp->flags & GS_REFERENCED)) + if ((lsp->flags & LS_WARN) && (sp->flags & GS_REFERENCED)) /* * Prevent warning symbols from getting * gratuitously referenced. @@ -1494,7 +1719,7 @@ enter_global_ref(lsp, name, entry) sp->refs = lsp; lsp->symbol = sp; - if (lsp->flags & LS_WARNING) { + if (lsp->flags & LS_WARN) { /* * Prevent warning symbols from getting * gratuitously referenced. @@ -1676,8 +1901,8 @@ enter_global_ref(lsp, name, entry) unsigned long contains_symbol(entry, np) - struct file_entry *entry; - register struct nlist *np; + struct file_entry *entry; + struct nlist *np; { if (np >= &entry->symbols->nzlist.nlist && np < &(entry->symbols + entry->nsymbols)->nzlist.nlist) @@ -2295,7 +2520,7 @@ consider_local_symbols(entry) register struct nlist *p = &lsp->nzlist.nlist; register int type = p->n_type; - if (type == N_WARNING) + if (type == N_WARN) continue; if (SET_ELEMENT_P (type)) { @@ -2530,7 +2755,7 @@ digest_pass2() /* Flag second-hand definitions */ undefined_global_sym_count++; if (sp->flags & GS_TRACE) - printf("symbol %s assigned to location %#x\n", + printf("symbol %s assigned to location %#lx\n", sp->name, sp->value); } @@ -2595,7 +2820,7 @@ digest_pass2() } bss_size += size; if (write_map) - printf("Allocating %s %s: %x at %x\n", + printf("Allocating %s %s: %x at %lx\n", sp->defined==(N_BSS|N_EXT)?"common":"data", sp->name, size, sp->value); @@ -3378,16 +3603,16 @@ static int strtab_index; static int assign_string_table_index(name) - char *name; + char *name; { - register int index = strtab_size; - register int len = strlen(name) + 1; + int index = strtab_size; + int len = strlen(name) + 1; strtab_size += len; strtab_vector[strtab_index] = name; strtab_lens[strtab_index++] = len; - return index; + return (index); } /* @@ -3482,11 +3707,11 @@ write_syms() continue; /* - * Propagate N_WARNING symbols. + * Propagate N_WARN symbols. */ if ((relocatable_output || building_shared_object) && sp->warning) { - nl.n_type = N_WARNING; + nl.n_type = N_WARN; nl.n_un.n_strx = assign_string_table_index(sp->warning); nl.n_value = 0; nl.n_other = 0; @@ -3562,7 +3787,7 @@ write_syms() nl.n_type = sp->defined; if (nl.n_type == (N_INDR|N_EXT) && sp->value != 0) - errx(1, "%s: N_INDR has value %#x", + errx(1, "%s: N_INDR has value %#lx", sp->name, sp->value); nl.n_value = sp->value; if (sp->def_lsp) @@ -3663,7 +3888,7 @@ printf("writesym(#%d): %s, type %x\n", syms_written, sp->name, sp->defined); if (symtab_offset + symtab_len != strtab_offset) errx(1, - "internal error: inconsistent symbol table length: %d vs %s", + "internal error: inconsistent symbol table length: %d vs %d", symtab_offset + symtab_len, strtab_offset); if (fseek(outstream, strtab_offset, SEEK_SET) != 0) diff --git a/gnu/usr.bin/ld/ld/ld_i.h b/gnu/usr.bin/ld/ld/ld_i.h new file mode 100644 index 00000000000..1c5d8cb0458 --- /dev/null +++ b/gnu/usr.bin/ld/ld/ld_i.h @@ -0,0 +1,444 @@ +/* $NetBSD: ld_i.h,v 1.1 1998/12/17 14:34:51 pk Exp $ */ +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Paul Kranenburg. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * This code is derived from software copyrighted by the Free Software + * Foundation. + * + * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. + * + * Linker `ld' for GNU + - Copyright (C) 1988 Free Software Foundation, Inc. + + - This program is free software; you can redistribute it and/or modify + - it under the terms of the GNU General Public License as published by + - the Free Software Foundation; either version 1, or (at your option) + - any later version. + + - This program is distributed in the hope that it will be useful, + - but WITHOUT ANY WARRANTY; without even the implied warranty of + - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + - GNU General Public License for more details. + + - You should have received a copy of the GNU General Public License + - along with this program; if not, write to the Free Software + - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * ld(1) implementation definitions. + */ + +#include <ranlib.h> + +/* Macro to control the number of undefined references printed */ +#define MAX_UREFS_PRINTED 10 + +/* Define this to specify the default executable format. */ +#ifndef DEFAULT_MAGIC +#ifdef __FreeBSD__ +#define DEFAULT_MAGIC QMAGIC +extern int netzmagic; +#else +#define DEFAULT_MAGIC ZMAGIC +#endif +#endif + +/* + * Internal representation of relocation types + */ +#define RELTYPE_EXTERN 1 +#define RELTYPE_JMPSLOT 2 +#define RELTYPE_BASEREL 4 +#define RELTYPE_RELATIVE 8 +#define RELTYPE_COPY 16 + +/* + * Local (wrt a compilation unit) symbol information. + */ +typedef struct localsymbol { + struct nzlist nzlist; /* n[z]list from file */ + struct glosym *symbol; /* Corresponding global symbol, + if any */ + struct localsymbol *next; /* List of definitions */ + struct file_entry *entry; /* Backpointer to file */ + long gotslot_offset; /* Position in GOT, if any */ + int symbolnum; /* Position in output nlist */ + int flags; +#define LS_L_SYMBOL 1 /* Local symbol starts with an `L' */ +#define LS_WRITE 2 /* Symbol goes in output symtable */ +#define LS_RENAME 4 /* xlat name to `<file>.<name>' */ +#define LS_HASGOTSLOT 8 /* This symbol has a GOT entry */ +#define LS_WARN 16 /* Second part of a N_WARN duo */ +} localsymbol_t; + +/* Symbol table */ + +/* + * Global symbol data is recorded in these structures, one for each global + * symbol. They are found via hashing in 'symtab', which points to a vector + * of buckets. Each bucket is a chain of these structures through the link + * field. + */ + +typedef struct glosym { + struct glosym *link; /* Next symbol hash bucket. */ + char *name; /* Name of this symbol. */ + long value; /* Value of this symbol */ + localsymbol_t *refs; /* Chain of local symbols from object + files pertaining to this global + symbol */ + localsymbol_t *sorefs;/* Same for local symbols from shared + object files. */ + + char *warning; /* message, from N_WARNING nlists */ + int common_size; /* Common size */ + int symbolnum; /* Symbol index in output symbol table */ + int rrs_symbolnum; /* Symbol index in RRS symbol table */ + + localsymbol_t *def_lsp; /* The local symbol that gave this + global symbol its definition */ + + char defined; /* Definition of this symbol */ + char so_defined; /* Definition of this symbol in a shared + object. These go into the RRS symbol table */ + u_char undef_refs; /* Count of number of "undefined" + messages printed for this symbol */ + u_char mult_defs; /* Same for "multiply defined" symbols */ + struct glosym *alias; /* For symbols of type N_INDR, this + points at the real symbol. */ + int setv_count; /* Number of elements in N_SETV symbols */ + int size; /* Size of this symbol (either from N_SIZE + symbols or a from shared object's RRS */ + int aux; /* Auxiliary type information conveyed in + the `n_other' field of nlists */ + + /* The offset into one of the RRS tables, -1 if not used */ + long jmpslot_offset; + long gotslot_offset; + + long flags; + +#define GS_DEFINED 0x1 /* Symbol has definition (notyetused)*/ +#define GS_REFERENCED 0x2 /* Symbol is referred to by something + interesting */ +#define GS_TRACE 0x4 /* Symbol will be traced */ +#define GS_HASJMPSLOT 0x8 /* */ +#define GS_HASGOTSLOT 0x10 /* Some state bits concerning */ +#define GS_CPYRELOCRESERVED 0x20 /* entries in GOT and PLT tables */ +#define GS_CPYRELOCCLAIMED 0x40 /* */ +#define GS_WEAK 0x80 /* Symbol is weakly defined */ + +} symbol; + +/* Number of buckets in symbol hash table */ +#define SYMTABSIZE 1009 + +/* The symbol hash table: a vector of SYMTABSIZE pointers to struct glosym. */ +extern symbol *symtab[]; +#define FOR_EACH_SYMBOL(i,sp) { \ + int i; \ + for (i = 0; i < SYMTABSIZE; i++) { \ + register symbol *sp; \ + for (sp = symtab[i]; sp; sp = sp->link) + +#define END_EACH_SYMBOL }} + +/* # of global symbols referenced and not defined. */ +extern int undefined_global_sym_count; + +/* # of weak symbols referenced and not defined. */ +extern int undefined_weak_sym_count; + +/* # of undefined symbols referenced by shared objects */ +extern int undefined_shobj_sym_count; + +/* # of multiply defined symbols. */ +extern int multiple_def_count; + +/* # of common symbols. */ +extern int common_defined_global_count; + +/* # of warning symbols encountered. */ +extern int warn_sym_count; +extern int list_warning_symbols; + +/* + * Define a linked list of strings which define symbols which should be + * treated as set elements even though they aren't. Any symbol with a prefix + * matching one of these should be treated as a set element. + * + * This is to make up for deficiencies in many assemblers which aren't willing + * to pass any stabs through to the loader which they don't understand. + */ +struct string_list_element { + char *str; + struct string_list_element *next; +}; + +extern symbol *entry_symbol; /* the entry symbol, if any */ +extern symbol *edata_symbol; /* the symbol _edata */ +extern symbol *etext_symbol; /* the symbol _etext */ +extern symbol *end_symbol; /* the symbol _end */ +extern symbol *got_symbol; /* the symbol __GLOBAL_OFFSET_TABLE_ */ +extern symbol *plt_symbol; /* the symbol __PROCEDURE_LINKAGE_TABLE_ */ +extern symbol *dynamic_symbol; /* the symbol __DYNAMIC */ + +/* + * Each input file, and each library member ("subfile") being loaded, has a + * `file_entry' structure for it. + * + * For files specified by command args, these are contained in the vector which + * `file_table' points to. + * + * For library members, they are dynamically allocated, and chained through the + * `chain' field. The chain is found in the `subfiles' field of the + * `file_entry'. The `file_entry' objects for the members have `superfile' + * fields pointing to the one for the library. + */ + +struct file_entry { + char *filename; /* Name of this file. */ + /* + * Name to use for the symbol giving address of text start Usually + * the same as filename, but for a file spec'd with -l this is the -l + * switch itself rather than the filename. + */ + char *local_sym_name; + struct exec header; /* The file's a.out header. */ + localsymbol_t *symbols; /* Symbol table of the file. */ + int nsymbols; /* Number of symbols in above array. */ + int string_size; /* Size in bytes of string table. */ + char *strings; /* Pointer to the string table when + in core, NULL otherwise */ + int strings_offset; /* Offset of string table, + (normally N_STROFF() + 4) */ + /* + * Next two used only if `relocatable_output' or if needed for + * output of undefined reference line numbers. + */ + struct relocation_info *textrel; /* Text relocations */ + int ntextrel; /* # of text relocations */ + struct relocation_info *datarel; /* Data relocations */ + int ndatarel; /* # of data relocations */ + + /* + * Relation of this file's segments to the output file. + */ + int text_start_address; /* Start of this file's text segment + in the output file core image. */ + int data_start_address; /* Start of this file's data segment + in the output file core image. */ + int bss_start_address; /* Start of this file's bss segment + in the output file core image. */ + struct file_entry *subfiles; /* For a library, points to chain of + entries for the library members. */ + struct file_entry *superfile; /* For library member, points to the + library's own entry. */ + struct file_entry *chain; /* For library member, points to next + entry for next member. */ + int starting_offset; /* For a library member, offset of the + member within the archive. Zero for + files that are not library members.*/ + int total_size; /* Size of contents of this file, + if library member. */ +#ifdef SUN_COMPAT + struct file_entry *silly_archive;/* For shared libraries which have + a .sa companion */ +#endif + int lib_major, lib_minor; /* Version numbers of a shared object */ + + int flags; +#define E_IS_LIBRARY 1 /* File is a an archive */ +#define E_HEADER_VALID 2 /* File's header has been read */ +#define E_SEARCH_DIRS 4 /* Search directories for file */ +#define E_SEARCH_DYNAMIC 8 /* Search for shared libs allowed */ +#define E_JUST_SYMS 0x10 /* File is used for incremental load */ +#define E_DYNAMIC 0x20 /* File is a shared object */ +#define E_SCRAPPED 0x40 /* Ignore this file */ +#define E_SYMBOLS_USED 0x80 /* Symbols from this entry were used */ +#define E_SECONDCLASS 0x100 /* Shared object is a subsidiary */ +}; + +/* + * Section start addresses. + */ +extern int text_size; /* total size of text. */ +extern int text_start; /* start of text */ +extern int text_pad; /* clear space between text and data */ +extern int data_size; /* total size of data. */ +extern int data_start; /* start of data */ +extern int data_pad; /* part of bss segment within data */ + +extern int bss_size; /* total size of bss. */ +extern int bss_start; /* start of bss */ + +extern int text_reloc_size; /* total size of text relocation. */ +extern int data_reloc_size; /* total size of data relocation. */ + +/* + * Runtime Relocation Section (RRS). + * This describes the data structures that go into the output text and data + * segments to support the run-time linker. The RRS can be empty (plain old + * static linking), or can just exist of GOT and PLT entries (in case of + * statically linked PIC code). + */ +extern int rrs_section_type; /* What's in the RRS section */ +#define RRS_NONE 0 +#define RRS_PARTIAL 1 +#define RRS_FULL 2 +extern int rrs_text_size; /* Size of RRS text additions */ +extern int rrs_text_start; /* Location of above */ +extern int rrs_data_size; /* Size of RRS data additions */ +extern int rrs_data_start; /* Location of above */ +extern char *rrs_search_paths; /* `-L' RT paths */ + +/* Version number to put in __DYNAMIC (set by -V) */ +extern int soversion; +#ifndef DEFAULT_SOVERSION +#define DEFAULT_SOVERSION LD_VERSION_BSD +#endif + +extern int pc_relocation; /* Current PC reloc value */ + +extern int number_of_shobjs; /* # of shared objects linked in */ + +/* Current link mode */ +extern int link_mode; +#define DYNAMIC 1 /* Consider shared libraries */ +#define SYMBOLIC 2 /* Force symbolic resolution */ +#define FORCEARCHIVE 4 /* Force inclusion of all members + of archives */ +#define SHAREABLE 8 /* Build a shared object */ +#define SILLYARCHIVE 16 /* Process .sa companions, if any */ + +extern FILE *outstream; /* Output file. */ +extern struct exec outheader; /* Output file header. */ +extern int magic; /* Output file magic. */ +extern int oldmagic; +extern int relocatable_output; +extern int pic_type; +#define PIC_TYPE_NONE 0 +#define PIC_TYPE_SMALL 1 +#define PIC_TYPE_LARGE 2 + +/* Size of a page. */ +extern int page_size; + +extern int write_map; /* write a load map (`-M') */ + +/* In ld.c: */ +void read_header __P((int, struct file_entry *)); +void read_entry_symbols __P((int, struct file_entry *)); +void read_entry_strings __P((int, struct file_entry *)); +void read_entry_relocation __P((int, struct file_entry *)); +void enter_file_symbols __P((struct file_entry *)); +void read_file_symbols __P((struct file_entry *)); +int set_element_prefixed_p __P((char *)); +int text_offset __P((struct file_entry *)); +int file_open __P((struct file_entry *)); +void each_file __P((void (*) __P((struct file_entry *, void *)), void *)); +void each_full_file __P((void (*)__P((struct file_entry *, void *)), void *)); +unsigned long check_each_file __P((unsigned long (*)__P((struct file_entry *, void *)), void *)); +void mywrite __P((void *, int, int, FILE *)); +void padfile __P((int, FILE *)); + +/* In warnings.c: */ +void perror_name __P((char *)); +void perror_file __P((struct file_entry *)); +void print_symbols __P((FILE *)); +char *get_file_name __P((struct file_entry *)); +void print_file_name __P((struct file_entry *, FILE *)); +void prline_file_name __P((struct file_entry *, FILE *)); +int do_warnings __P((FILE *)); + +/* In symbol.c: */ +void symtab_init __P((int)); +symbol *getsym __P((char *)), *getsym_soft __P((char *)); + +/* In lib.c: */ +void search_library __P((int, struct file_entry *)); +void read_shared_object __P((int, struct file_entry *)); +int findlib __P((struct file_entry *)); + +/* In rrs.c: */ +void init_rrs __P((void)); +int rrs_add_shobj __P((struct file_entry *)); +void alloc_rrs_reloc __P((struct file_entry *, symbol *)); +void alloc_rrs_segment_reloc __P((struct file_entry *, + struct relocation_info *)); +void alloc_rrs_jmpslot __P((struct file_entry *, symbol *)); +void alloc_rrs_gotslot __P((struct file_entry *, struct relocation_info *, + localsymbol_t *)); +void alloc_rrs_cpy_reloc __P((struct file_entry *, symbol *)); + +int claim_rrs_reloc __P((struct file_entry *, struct relocation_info *, + symbol *, long *)); +long claim_rrs_jmpslot __P((struct file_entry *, struct relocation_info *, + symbol *, long)); +long claim_rrs_gotslot __P((struct file_entry *, struct relocation_info *, + struct localsymbol *, long)); +long claim_rrs_internal_gotslot __P((struct file_entry *, + struct relocation_info *, + struct localsymbol *, long)); +void claim_rrs_cpy_reloc __P((struct file_entry *, + struct relocation_info *, symbol *)); +void claim_rrs_segment_reloc __P((struct file_entry *, + struct relocation_info *)); +void consider_rrs_section_lengths __P((void)); +void relocate_rrs_addresses __P((void)); +void write_rrs __P((void)); + +void swap_longs __P((long *, int)); + +void md_swapin_exec_hdr __P((struct exec *)); +void md_swapout_exec_hdr __P((struct exec *)); +void md_swapin_reloc __P((struct relocation_info *, int)); +void md_swapout_reloc __P((struct relocation_info *, int)); +void md_swapout_jmpslot __P((jmpslot_t *, int)); + +/* In xbits.c: */ +void swap_symbols __P((struct nlist *, int)); +void swap_zsymbols __P((struct nzlist *, int)); +void swap_ranlib_hdr __P((struct ranlib *, int)); +void swap__dynamic __P((struct _dynamic *)); +void swap_section_dispatch_table __P((struct section_dispatch_table *)); +void swap_so_debug __P((struct so_debug *)); +void swapin_sod __P((struct sod *, int)); +void swapout_sod __P((struct sod *, int)); +void swap_rrs_hash __P((struct rrs_hash *, int)); +/*void swapout_fshash __P((struct fshash *, int));*/ diff --git a/gnu/usr.bin/ld/ld/lib.c b/gnu/usr.bin/ld/ld/lib.c index 12247baeaee..6dd36a5811b 100644 --- a/gnu/usr.bin/ld/ld/lib.c +++ b/gnu/usr.bin/ld/ld/lib.c @@ -1,13 +1,10 @@ -/* $NetBSD: lib.c,v 1.18 1998/10/17 17:14:01 itohy Exp $ */ +/* $NetBSD: lib.c,v 1.19 1998/12/17 14:34:51 pk Exp $ */ /* * - library routines */ #include <sys/param.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/file.h> @@ -16,13 +13,18 @@ #include <fcntl.h> #include <ar.h> #include <ranlib.h> -#include <a.out.h> #include <stab.h> -#include <string.h> -#include <dirent.h> #include <ctype.h> +#include <dirent.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <a.out.h> +#include "shlib.h" #include "ld.h" +#include "ld_i.h" static void linear_library __P((int, struct file_entry *)); static void symdef_library __P((int, struct file_entry *, int)); @@ -80,15 +82,16 @@ decode_library_subfile(fd, library_entry, subfile_offset, length_loc) int subfile_offset; int *length_loc; { - int bytes_read; - register int namelen; - int member_length, content_length; - int starting_offset; - register char *name; - struct ar_hdr hdr1; - register struct file_entry *subentry; + int bytes_read; + int namelen; + int member_length, content_length; + int starting_offset; + char *name; + struct ar_hdr hdr1; + struct file_entry *subentry; - lseek(fd, subfile_offset, 0); + if (lseek(fd, subfile_offset, SEEK_SET) == -1) + return (NULL); bytes_read = read(fd, &hdr1, sizeof hdr1); if (!bytes_read) @@ -104,7 +107,7 @@ decode_library_subfile(fd, library_entry, subfile_offset, length_loc) if (sscanf(hdr1.ar_size, "%d", &member_length) != 1) errx(1, "%s: malformatted header of archive member: %.*s", get_file_name(library_entry), - sizeof(hdr1.ar_name), hdr1.ar_name); + (int)sizeof(hdr1.ar_name), hdr1.ar_name); subentry = (struct file_entry *) xmalloc(sizeof(struct file_entry)); bzero(subentry, sizeof(struct file_entry)); @@ -131,7 +134,7 @@ decode_library_subfile(fd, library_entry, subfile_offset, length_loc) if (read(fd, name, namelen) != namelen) errx(1, "%s: malformatted archive member: %.*s", get_file_name(library_entry), - sizeof(hdr1.ar_name), hdr1.ar_name); + (int)sizeof(hdr1.ar_name), hdr1.ar_name); name[namelen] = 0; content_length -= namelen; starting_offset += namelen; @@ -157,9 +160,9 @@ decode_library_subfile(fd, library_entry, subfile_offset, length_loc) subentry->flags = 0; #endif - (*length_loc) = member_length; + *length_loc = member_length; - return subentry; + return (subentry); } static int subfile_wanted_p __P((struct file_entry *)); @@ -177,16 +180,16 @@ symdef_library(fd, entry, member_length) struct file_entry *entry; int member_length; { - int *symdef_data = (int *) xmalloc(member_length); - register struct ranlib *symdef_base; - char *sym_name_base; - int nsymdefs; - int length_of_strings; - int not_finished; - int bytes_read; - register int i; + int *symdef_data = (int *) xmalloc(member_length); + struct ranlib *symdef_base; + char *sym_name_base; + int nsymdefs; + int length_of_strings; + int not_finished; + int bytes_read; + int i; struct file_entry *prev = 0; - int prev_offset = 0; + int prev_offset = 0; bytes_read = read(fd, symdef_data, member_length); if (bytes_read != member_length) @@ -242,9 +245,9 @@ symdef_library(fd, entry, member_length) common_defined_global_count)); i++) { register symbol *sp; - int junk; - register int j; - register int offset = symdef_base[i].ran_off; + int junk; + int j; + int offset = symdef_base[i].ran_off; struct file_entry *subentry; @@ -369,19 +372,20 @@ linear_library(fd, entry) int fd; struct file_entry *entry; { - register struct file_entry *prev = 0; - register int this_subfile_offset = SARMAG; + struct file_entry *prev = 0; + int this_subfile_offset = SARMAG; while ((link_mode & FORCEARCHIVE) || undefined_global_sym_count || common_defined_global_count) { - int member_length; - register struct file_entry *subentry; + int member_length; + struct file_entry *subentry; subentry = decode_library_subfile(fd, entry, - this_subfile_offset, &member_length); + this_subfile_offset, + &member_length); - if (!subentry) + if (subentry == NULL) return; read_entry_symbols(fd, subentry); @@ -389,7 +393,7 @@ linear_library(fd, entry) read_entry_strings(fd, subentry); if (!(link_mode & FORCEARCHIVE) && - !subfile_wanted_p(subentry)) { + !subfile_wanted_p(subentry)) { if (subentry->symbols) free(subentry->symbols); free(subentry->filename); @@ -830,7 +834,7 @@ struct file_entry *p; dot_a: p->flags &= ~E_SEARCH_DYNAMIC; - if (cp = strrchr(p->filename, '/')) { + if ((cp = strrchr(p->filename, '/')) != NULL) { *cp++ = '\0'; fname = concat(concat(p->filename, "/lib", cp), ".a", ""); *(--cp) = '/'; diff --git a/gnu/usr.bin/ld/ld/rrs.c b/gnu/usr.bin/ld/ld/rrs.c index 679474185d8..51270810350 100644 --- a/gnu/usr.bin/ld/ld/rrs.c +++ b/gnu/usr.bin/ld/ld/rrs.c @@ -1,4 +1,4 @@ -/* $NetBSD: rrs.c,v 1.26 1998/10/19 03:09:34 matt Exp $ */ +/* $NetBSD: rrs.c,v 1.27 1998/12/17 14:34:51 pk Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -52,7 +52,9 @@ #include <stab.h> #include <string.h> +#include "shlib.h" #include "ld.h" +#include "ld_i.h" static struct _dynamic rrs_dyn; /* defined in link.h */ static struct so_debug rrs_so_debug; /* defined in link.h */ @@ -83,10 +85,16 @@ static int current_got_offset; static int max_got_offset; static int min_got_offset; static int got_origin; -static int current_reloc_offset; static int current_hash_index; int number_of_shobjs; +/* */ +static struct relocation_info *rrs_next_reloc __P((void)); +static void rrs_insert_hash __P((char *, int)); +static void write_rrs_data __P((void)); +static void write_rrs_text __P((void)); + + /* Convert a GOT offset into a table entry */ #define GOTP(off) ((got_t *)((long)rrs_got + got_origin + (off))) @@ -536,10 +544,11 @@ claim_rrs_internal_gotslot(entry, rp, lsp, addend) if (lsp->gotslot_offset != -1) { /* Already claimed */ if (*GOTP(lsp->gotslot_offset) != addend) - errx(1, "%s: gotslot at %#x is multiple valued: %#x vs %#x", - get_file_name(entry), lsp->gotslot_offset, - *GOTP(lsp->gotslot_offset), addend); - return lsp->gotslot_offset; + errx(1, + "%s: gotslot at %#lx is multiple valued: %#lx vs %#lx", + get_file_name(entry), lsp->gotslot_offset, + *GOTP(lsp->gotslot_offset), addend); + return (lsp->gotslot_offset); } if (current_got_offset == 0) @@ -572,7 +581,7 @@ printf("claim_rrs_internal_gotslot: %s: slot offset %#x, addend = %#x\n", r->r_address = got_symbol->value + lsp->gotslot_offset; RELOC_EXTERN_P(r) = 0; md_make_gotreloc(rp, r, RELTYPE_RELATIVE); - return lsp->gotslot_offset; + return (lsp->gotslot_offset); } void @@ -672,9 +681,10 @@ void consider_rrs_section_lengths() { int n; - struct shobj *shp, **shpp; + struct shobj *shp; #ifdef notyet + struct shobj **shpp; /* We run into trouble with this as long as shared object symbols are not checked for definitions */ /* @@ -764,7 +774,7 @@ consider_rrs_section_lengths() dynamic_symbol->rrs_symbolnum = number_of_rrs_symbols++; FOR_EACH_SYMBOL(i ,sp) { if ((link_mode & SHAREABLE) && sp->warning) { - /* Allocate N_WARNING & co */ + /* Allocate N_WARN & co */ rrs_strtab_size += 2 + strlen(sp->name) + strlen(sp->warning); number_of_rrs_symbols += 2; @@ -1050,9 +1060,9 @@ write_rrs_text() if ((link_mode & SHAREABLE) && sp->warning) { /* - * Write a N_WARNING duo. + * Write a N_WARN duo. */ - nlp->nz_type = N_WARNING; + nlp->nz_type = N_WARN; nlp->nz_un.n_strx = offset; nlp->nz_value = 0; nlp->nz_other = 0; diff --git a/gnu/usr.bin/ld/ld/symbol.c b/gnu/usr.bin/ld/ld/symbol.c index f949e2c8319..96b26c67e53 100644 --- a/gnu/usr.bin/ld/ld/symbol.c +++ b/gnu/usr.bin/ld/ld/symbol.c @@ -1,4 +1,4 @@ -/* $NetBSD: symbol.c,v 1.14 1998/09/04 09:43:29 pk Exp $ */ +/* $NetBSD: symbol.c,v 1.15 1998/12/17 14:34:52 pk Exp $ */ /* * - symbol table routines @@ -15,7 +15,9 @@ #include <stdlib.h> #include <string.h> +#include "shlib.h" #include "ld.h" +#include "ld_i.h" symbol *symtab[SYMTABSIZE]; /* The symbol table. */ int num_hash_tab_syms; /* Number of symbols in symbol hash table. */ @@ -27,6 +29,8 @@ symbol *got_symbol; /* the symbol __GLOBAL_OFFSET_TABLE_ */ symbol *plt_symbol; /* the symbol __PROCEDURE_LINKAGE_TABLE_ */ symbol *dynamic_symbol; /* the symbol __DYNAMIC */ +static int hash_string __P((char *)); + void symtab_init(relocatable_output) int relocatable_output; @@ -63,7 +67,6 @@ symtab_init(relocatable_output) /* * Compute the hash code for symbol name KEY. */ - int hash_string (key) char *key; diff --git a/gnu/usr.bin/ld/ld/warnings.c b/gnu/usr.bin/ld/ld/warnings.c index fdfa1335a9c..0b8de498b14 100644 --- a/gnu/usr.bin/ld/ld/warnings.c +++ b/gnu/usr.bin/ld/ld/warnings.c @@ -1,4 +1,4 @@ -/* $NetBSD: warnings.c,v 1.22 1998/12/15 22:34:38 pk Exp $ */ +/* $NetBSD: warnings.c,v 1.23 1998/12/17 14:34:52 pk Exp $ */ #include <sys/param.h> #include <sys/types.h> @@ -21,7 +21,9 @@ #include <varargs.h> #endif +#include "shlib.h" #include "ld.h" +#include "ld_i.h" static int reported_undefineds; @@ -109,7 +111,7 @@ print_symbols(outfile) else if (sp->defined == (N_UNDF|N_EXT)) fprintf(outfile, "common: size %#x", sp->common_size); else - fprintf(outfile, "type %d, value %#x, size %#x", + fprintf(outfile, "type %d, value %#lx, size %#x", sp->defined, sp->value, sp->size); if (!(sp->flags & GS_REFERENCED)) fprintf(outfile, ", unreferenced"); @@ -131,7 +133,8 @@ describe_file_sections(entry, outfile) if (entry->flags & (E_JUST_SYMS | E_DYNAMIC)) fprintf(outfile, " symbols only\n"); else - fprintf(outfile, " text %x(%x), data %x(%x), bss %x(%x) hex\n", + fprintf(outfile, + " text %#x(%#lx), data %#x(%#lx), bss %#x(%#lx)\n", entry->text_start_address, entry->header.a_text, entry->data_start_address, entry->header.a_data, entry->bss_start_address, entry->header.a_bss); @@ -159,7 +162,7 @@ list_file_locals (entry, outfile) * update it if necessary by this file's start address. */ if (!(p->n_type & (N_STAB | N_EXT))) - fprintf(outfile, " %s: 0x%x\n", + fprintf(outfile, " %s: %#lx\n", entry->strings + p->n_un.n_strx, p->n_value); } @@ -186,9 +189,17 @@ struct line_debug_entry struct localsymbol *sym; }; + +static void do_file_warnings __P((struct file_entry *, void *)); + /* * Helper routines for do_file_warnings. */ +static int reloc_cmp __P((const void *, const void *)); +static int next_debug_entry __P((int, struct line_debug_entry[])); +static void do_relocation_warnings __P((struct file_entry *, int, + FILE *, unsigned char *)); +static int address_to_line __P((unsigned long, struct line_debug_entry [])); /* * Return an integer less than, equal to, or greater than 0 as per the @@ -196,9 +207,13 @@ struct line_debug_entry */ static int -reloc_cmp(rel1, rel2) - struct relocation_info *rel1, *rel2; +reloc_cmp(v1, v2) + const void *v1; + const void *v2; { + const struct relocation_info *rel1 = v1; + const struct relocation_info *rel2 = v2; + return RELOC_ADDRESS(rel1) - RELOC_ADDRESS(rel2); } @@ -386,7 +401,7 @@ address_to_line(address, state_pointer) /* * This routine will scan through the relocation data of file ENTRY, printing * out references to undefined symbols and references to symbols defined in - * files with N_WARNING symbols. If DATA_SEGMENT is non-zero, it will scan + * files with N_WARN symbols. If DATA_SEGMENT is non-zero, it will scan * the data relocation segment (and use N_DSLINE symbols to track line * number); otherwise it will scan the text relocation segment. Warnings * will be printed on the output stream OUTFILE. Eventually, every nlist @@ -534,10 +549,11 @@ do_relocation_warnings(entry, data_segment, outfile, nlist_bitvector) */ void -do_file_warnings (entry, outfile) +do_file_warnings (entry, arg) struct file_entry *entry; - FILE *outfile; + void *arg; { + FILE *outfile = arg; int nsym; int i; char *errfmt, *file_name; @@ -546,6 +562,8 @@ do_file_warnings (entry, outfile) u_char *nlist_bitvector; struct line_debug_entry *text_scan, *data_scan; + file_name = "<GCC induced initialization - should never print>"; + nsym = entry->nsymbols; nlist_bitvector = (u_char *)alloca((nsym >> 3) + 1); bzero(nlist_bitvector, (nsym >> 3) + 1); @@ -657,7 +675,7 @@ do_file_warnings (entry, outfile) "of symbol `%s', type %#x", get_file_name(entry), g->name, np->n_type); - break; + continue; } } else if (BIT_SET_P(nlist_bitvector, i)) { @@ -691,7 +709,7 @@ do_file_warnings (entry, outfile) * used by the warning stabs itself. */ if (np->n_type != (N_EXT | N_UNDF) || - (entry->symbols[i].flags & LS_WARNING)) + (entry->symbols[i].flags & LS_WARN)) continue; errfmt = g->warning; diff --git a/gnu/usr.bin/ld/ld/xbits.c b/gnu/usr.bin/ld/ld/xbits.c index fcbb3c72990..7cea2fbc6ed 100644 --- a/gnu/usr.bin/ld/ld/xbits.c +++ b/gnu/usr.bin/ld/ld/xbits.c @@ -1,4 +1,4 @@ -/* $NetBSD: xbits.c,v 1.6 1998/09/05 13:08:40 pk Exp $ */ +/* $NetBSD: xbits.c,v 1.7 1998/12/17 14:34:52 pk Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -40,25 +40,20 @@ * "Generic" byte-swap routines. */ -#include <sys/param.h> -#include <stdio.h> -#include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/file.h> -#include <fcntl.h> -#include <ar.h> -#include <ranlib.h> #include <a.out.h> -#include <stab.h> -#include <string.h> +#include <stdio.h> +#include <stdlib.h> #include "ld.h" +#include "ld_i.h" void swap_longs(lp, n) -int n; -long *lp; + int n; + long *lp; { for (; n > 0; n--, lp++) *lp = md_swap_long(*lp); @@ -66,8 +61,8 @@ long *lp; void swap_symbols(s, n) -struct nlist *s; -int n; + struct nlist *s; + int n; { for (; n; n--, s++) { s->n_un.n_strx = md_swap_long(s->n_un.n_strx); @@ -78,8 +73,8 @@ int n; void swap_zsymbols(s, n) -struct nzlist *s; -int n; + struct nzlist *s; + int n; { for (; n; n--, s++) { s->nz_strx = md_swap_long(s->nz_strx); @@ -92,8 +87,8 @@ int n; void swap_ranlib_hdr(rlp, n) -struct ranlib *rlp; -int n; + struct ranlib *rlp; + int n; { for (; n; n--, rlp++) { rlp->ran_un.ran_strx = md_swap_long(rlp->ran_un.ran_strx); @@ -103,7 +98,7 @@ int n; void swap__dynamic(dp) -struct _dynamic *dp; + struct _dynamic *dp; { dp->d_version = md_swap_long(dp->d_version); dp->d_debug = (struct so_debug *)md_swap_long((long)dp->d_debug); @@ -114,22 +109,22 @@ struct _dynamic *dp; void swap_section_dispatch_table(sdp) -struct section_dispatch_table *sdp; + struct section_dispatch_table *sdp; { swap_longs((long *)sdp, sizeof(*sdp)/sizeof(long)); } void swap_so_debug(ddp) -struct so_debug *ddp; + struct so_debug *ddp; { swap_longs((long *)ddp, sizeof(*ddp)/sizeof(long)); } void swapin_sod(sodp, n) -struct sod *sodp; -int n; + struct sod *sodp; + int n; { unsigned long bits; @@ -145,8 +140,8 @@ int n; void swapout_sod(sodp, n) -struct sod *sodp; -int n; + struct sod *sodp; + int n; { unsigned long bits; @@ -162,12 +157,11 @@ int n; void swap_rrs_hash(fsp, n) -struct rrs_hash *fsp; -int n; + struct rrs_hash *fsp; + int n; { for (; n; n--, fsp++) { fsp->rh_symbolnum = md_swap_long(fsp->rh_symbolnum); fsp->rh_next = md_swap_long(fsp->rh_next); } } - |
