1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-04 23:35:36 -08:00

Remove more knowledge of a.out and stab information from the tree.

ok miod
This commit is contained in:
deraadt 2013-10-19 09:00:18 +00:00
parent 36469d4f36
commit c54927cb82
8 changed files with 11 additions and 964 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.176 2013/09/29 14:54:07 deraadt Exp $
# $OpenBSD: Makefile,v 1.177 2013/10/19 09:00:18 deraadt Exp $
# $NetBSD: Makefile,v 1.59 1996/05/15 21:36:43 jtc Exp $
# @(#)Makefile 5.45.1.1 (Berkeley) 5/6/91
@ -17,13 +17,13 @@ FILES= a.out.h ar.h assert.h bitstring.h blf.h bm.h bsd_auth.h \
md5.h memory.h mpool.h ndbm.h netdb.h netgroup.h nlist.h nl_types.h \
ohash.h paths.h poll.h pwd.h ranlib.h re_comp.h \
readpassphrase.h regex.h resolv.h rmd160.h search.h setjmp.h \
sgtty.h sha1.h sha2.h signal.h sndio.h spawn.h stab.h \
sgtty.h sha1.h sha2.h signal.h sndio.h spawn.h \
stdbool.h stddef.h stdio.h stdlib.h \
string.h strings.h struct.h sysexits.h tar.h tgmath.h \
time.h ttyent.h tzfile.h unistd.h utime.h utmp.h vis.h \
wchar.h wctype.h
FILES+= link.h link_aout.h link_elf.h
FILES+= link.h link_elf.h
.if (${MACHINE_ARCH} != "vax")
FILES+= ieeefp.h

View File

@ -1,4 +1,4 @@
/* $OpenBSD: link.h,v 1.14 2004/01/22 21:48:02 espie Exp $ */
/* $OpenBSD: link.h,v 1.15 2013/10/19 09:00:18 deraadt Exp $ */
/* $NetBSD: link.h,v 1.10 1996/01/09 00:00:11 pk Exp $ */
/*
@ -37,8 +37,6 @@
#ifdef __ELF__
#include <link_elf.h>
#else
#include <link_aout.h>
#endif
/*

View File

@ -1,204 +0,0 @@
/* $OpenBSD: link_aout.h,v 1.2 2004/01/22 21:48:02 espie Exp $ */
/*
* Copyright (c) 1993 Paul Kranenburg
* All rights reserved.
*
* 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 Paul Kranenburg.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
/*
* RRS section definitions.
*
* The layout of some data structures defined in this header file is
* such that we can provide compatibility with the SunOS 4.x shared
* library scheme.
*/
/*
* Symbol description with size. This is simply an `nlist' with
* one field (nz_size) added.
* Used to convey size information on items in the data segment
* of shared objects. An array of these live in the shared object's
* text segment and is addressed by the `sdt_nzlist' field.
*/
struct nzlist {
struct nlist nlist;
unsigned long nz_size;
#define nz_un nlist.n_un
#define nz_strx nlist.n_un.n_strx
#define nz_name nlist.n_un.n_name
#define nz_type nlist.n_type
#define nz_value nlist.n_value
#define nz_desc nlist.n_desc
#define nz_other nlist.n_other
};
#define N_AUX(p) ((p)->n_other & 0xf)
#define N_BIND(p) (((unsigned int)(p)->n_other >> 4) & 0xf)
#define N_OTHER(r, v) (((unsigned int)(r) << 4) | ((v) & 0xf))
#define AUX_OBJECT 1
#define AUX_FUNC 2
/*#define BIND_LOCAL 0 not used */
/*#define BIND_GLOBAL 1 not used */
#define BIND_WEAK 2
/*
* The `section_dispatch_table' structure contains offsets to various data
* structures needed to do run-time relocation.
*/
struct section_dispatch_table {
struct so_map *sdt_loaded; /* List of loaded objects */
long sdt_sods; /* List of shared objects descriptors */
long sdt_paths; /* Library search paths */
long sdt_got; /* Global offset table */
long sdt_plt; /* Procedure linkage table */
long sdt_rel; /* Relocation table */
long sdt_hash; /* Symbol hash table */
long sdt_nzlist; /* Symbol table itself */
long sdt_filler2; /* Unused (was: stab_hash) */
long sdt_buckets; /* Number of hash buckets */
long sdt_strings; /* Symbol strings */
long sdt_str_sz; /* Size of symbol strings */
long sdt_text_sz; /* Size of text area */
long sdt_plt_sz; /* Size of procedure linkage table */
};
/*
* RRS symbol hash table, addressed by `sdt_hash' in section_dispatch_table.
* Used to quickly lookup symbols of the shared object by hashing
* on the symbol's name. `rh_symbolnum' is the index of the symbol
* in the shared object's symbol list (`sdt_nzlist'), `rh_next' is
* the next symbol in the hash bucket (in case of collisions).
*/
struct rrs_hash {
int rh_symbolnum; /* Symbol number */
int rh_next; /* Next hash entry */
};
/*
* `rt_symbols' is used to keep track of run-time allocated commons
* and data items copied from shared objects.
*/
struct rt_symbol {
struct nzlist *rt_sp; /* The symbol */
struct rt_symbol *rt_next; /* Next in linear list */
struct rt_symbol *rt_link; /* Next in bucket */
caddr_t rt_srcaddr; /* Address of "master" copy */
struct so_map *rt_smp; /* Originating map */
};
/*
* Debugger interface structure.
*/
struct so_debug {
int dd_version; /* Version # of interface */
int dd_in_debugger; /* Set when run by debugger */
int dd_sym_loaded; /* Run-time linking brought more
symbols into scope */
char *dd_bpt_addr; /* Address of rtld-generated bpt */
int dd_bpt_shadow; /* Original contents of bpt */
struct rt_symbol *dd_cc; /* Allocated commons/copied data */
};
/*
* Entry points into ld.so - user interface to the run-time linker.
*/
struct ld_entry {
void *(*dlopen)(const char *, int);
int (*dlclose)(void *);
void *(*dlsym)(void *, const char *);
int (*dlctl)(void *, int, void *);
void (*dlexit)(void);
void (*dlrsrvd[3])(void);
};
/*
* This is the structure pointed at by the __DYNAMIC symbol if an
* executable requires the attention of the run-time link editor.
* __DYNAMIC is given the value zero if no run-time linking needs to
* be done (it is always present in shared objects).
* The union `d_un' provides for different versions of the dynamic
* linking mechanism (switched on by `d_version'). The last version
* used by Sun is 3. We leave some room here and go to version number
* 8 for NetBSD, the main difference lying in the support for the
* `nz_list' type of symbols.
*/
struct _dynamic {
int d_version; /* version # of this interface */
struct so_debug *d_debug;
union {
struct section_dispatch_table *d_sdt;
} d_un;
struct ld_entry *d_entry; /* compat - now in crt_ldso */
};
#define LD_VERSION_SUN (3)
#define LD_VERSION_BSD (8)
#define LD_VERSION_NZLIST_P(v) ((v) >= 8)
#define LD_GOT(x) ((x)->d_un.d_sdt->sdt_got)
#define LD_PLT(x) ((x)->d_un.d_sdt->sdt_plt)
#define LD_REL(x) ((x)->d_un.d_sdt->sdt_rel)
#define LD_SYMBOL(x) ((x)->d_un.d_sdt->sdt_nzlist)
#define LD_HASH(x) ((x)->d_un.d_sdt->sdt_hash)
#define LD_STRINGS(x) ((x)->d_un.d_sdt->sdt_strings)
#define LD_NEED(x) ((x)->d_un.d_sdt->sdt_sods)
#define LD_BUCKETS(x) ((x)->d_un.d_sdt->sdt_buckets)
#define LD_PATHS(x) ((x)->d_un.d_sdt->sdt_paths)
#define LD_GOTSZ(x) ((x)->d_un.d_sdt->sdt_plt - (x)->d_un.d_sdt->sdt_got)
#define LD_RELSZ(x) ((x)->d_un.d_sdt->sdt_hash - (x)->d_un.d_sdt->sdt_rel)
#define LD_HASHSZ(x) ((x)->d_un.d_sdt->sdt_nzlist - (x)->d_un.d_sdt->sdt_hash)
#define LD_STABSZ(x) ((x)->d_un.d_sdt->sdt_strings - (x)->d_un.d_sdt->sdt_nzlist)
#define LD_PLTSZ(x) ((x)->d_un.d_sdt->sdt_plt_sz)
#define LD_STRSZ(x) ((x)->d_un.d_sdt->sdt_str_sz)
#define LD_TEXTSZ(x) ((x)->d_un.d_sdt->sdt_text_sz)
/*
* Interface to ld.so
*/
struct crt_ldso {
int crt_ba; /* Base address of ld.so */
int crt_dzfd; /* "/dev/zero" file descriptor (SunOS) */
int crt_ldfd; /* ld.so file descriptor */
struct _dynamic *crt_dp; /* Main's __DYNAMIC */
char **crt_ep; /* environment strings */
caddr_t crt_bp; /* Breakpoint if run from debugger */
char *crt_prog; /* Program name (v3) */
char *crt_ldso; /* Link editor name (v4) */
struct ld_entry *crt_ldentry; /* dl*() access (v4) */
};
/*
* Version passed from crt0 to ld.so (1st argument to _rtld()).
*/
#define CRT_VERSION_SUN 1
#define CRT_VERSION_BSD_2 2
#define CRT_VERSION_BSD_3 3
#define CRT_VERSION_BSD_4 4

View File

@ -1,71 +0,0 @@
/* $OpenBSD: stab.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */
/* $NetBSD: stab.h,v 1.4 1994/10/26 00:56:25 cgd Exp $ */
/*-
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
*
* 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. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*
* @(#)stab.h 5.2 (Berkeley) 4/4/91
*/
#ifndef _STAB_H_
#define _STAB_H_
/*
* The following are symbols used by various debuggers and by the Pascal
* compiler. Each of them must have one (or more) of the bits defined by
* the N_STAB mask set.
*/
#define N_GSYM 0x20 /* global symbol */
#define N_FNAME 0x22 /* F77 function name */
#define N_FUN 0x24 /* procedure name */
#define N_STSYM 0x26 /* data segment variable */
#define N_LCSYM 0x28 /* bss segment variable */
#define N_MAIN 0x2a /* main function name */
#define N_PC 0x30 /* global Pascal symbol */
#define N_RSYM 0x40 /* register variable */
#define N_SLINE 0x44 /* text segment line number */
#define N_DSLINE 0x46 /* data segment line number */
#define N_BSLINE 0x48 /* bss segment line number */
#define N_SSYM 0x60 /* structure/union element */
#define N_SO 0x64 /* main source file name */
#define N_LSYM 0x80 /* stack variable */
#define N_BINCL 0x82 /* include file beginning */
#define N_SOL 0x84 /* included source file name */
#define N_PSYM 0xa0 /* parameter variable */
#define N_EINCL 0xa2 /* include file end */
#define N_ENTRY 0xa4 /* alternate entry point */
#define N_LBRAC 0xc0 /* left bracket */
#define N_EXCL 0xc2 /* deleted include file */
#define N_RBRAC 0xe0 /* right bracket */
#define N_BCOMM 0xe2 /* begin common */
#define N_ECOMM 0xe4 /* end common */
#define N_ECOML 0xe8 /* end common (local name) */
#define N_LENG 0xfe /* length of preceding entry */
#endif /* !_STAB_H_ */

View File

@ -1,9 +1,7 @@
# $OpenBSD: Makefile,v 1.47 2013/07/09 18:25:28 miod Exp $
# $OpenBSD: Makefile,v 1.48 2013/10/19 09:00:19 deraadt Exp $
# $NetBSD: Makefile,v 1.14 1995/05/11 23:13:15 cgd Exp $
# missing: dump.5 plot.5
MAN= a.out.5 acct.5 ar.5 bsd.port.mk.5 bsd.port.arch.mk.5 bsd.regress.mk.5 \
MAN= acct.5 ar.5 bsd.port.mk.5 bsd.port.arch.mk.5 bsd.regress.mk.5 \
changelist.5 core.5 \
defaultdomain.5 dir.5 disktab.5 elf.5 ethers.5 fbtab.5 files.conf.5 \
forward.5 fs.5 fstab.5 genassym.cf.5 group.5 hostname.if.5 \
@ -12,7 +10,7 @@ MAN= a.out.5 acct.5 ar.5 bsd.port.mk.5 bsd.port.arch.mk.5 bsd.regress.mk.5 \
pf.conf.5 pf.os.5 port-modules.5 printcap.5 protocols.5 \
ranlib.5 remote.5 resolv.conf.5 rpc.5 ruby-module.5 \
services.5 shells.5 \
stab.5 spamd.conf.5 sysctl.conf.5 utmp.5 wsconsctl.conf.5
spamd.conf.5 sysctl.conf.5 utmp.5 wsconsctl.conf.5
MLINKS= dir.5 dirent.5 fs.5 inode.5 utmp.5 wtmp.5 utmp.5 lastlog.5
MLINKS+= hosts.equiv.5 .rhosts.5

View File

@ -1,449 +0,0 @@
.\" $OpenBSD: a.out.5,v 1.17 2013/07/10 06:43:38 jmc Exp $
.\" $NetBSD: a.out.5,v 1.8 1994/11/30 19:31:09 jtc Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This man page is derived from documentation contributed to Berkeley by
.\" Donn Seeley at UUNET Technologies, Inc.
.\"
.\" 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. Neither the name of the University 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 REGENTS 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 REGENTS 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.
.\"
.\" @(#)a.out.5 8.1 (Berkeley) 6/5/93
.\"
.Dd $Mdocdate: July 10 2013 $
.Dt A.OUT 5
.Os
.Sh NAME
.Nm a.out
.Nd format of legacy executable binary files
.Sh SYNOPSIS
.Fd #include <sys/types.h>
.Fd #include <a.out.h>
.Sh DESCRIPTION
The include file
.Aq Pa a.out.h
declares three structures and several macros.
The structures describe the format of legacy executable machine code files
.Pq Dq binaries
on the system.
.Pp
A binary file consists of up to 7 sections.
In order, these sections are:
.Bl -tag -width "text relocations"
.It exec header
Contains parameters used by the kernel to load a binary file into memory
and execute it, and by the link editor
.Xr ld 1
to combine a binary file with other binary files.
This section is the only mandatory one.
.It text segment
Contains machine code and related data
that are loaded into memory when a program executes.
May be loaded read-only.
.It data segment
Contains initialized data; always loaded into writable memory.
.It text relocations
Contains records used by the link editor
to update pointers in the text segment when combining binary files.
.It data relocations
Like the text relocation section, but for data segment pointers.
.It symbol table
Contains records used by the link editor
to cross reference the addresses of named variables and functions
.Pq Dq symbols
between binary files.
.It string table
Contains the character strings corresponding to the symbol names.
.El
.Pp
Every binary file begins with an
.Fa exec
structure:
.Bd -literal -offset indent
struct exec {
u_int32_t a_midmag;
u_int32_t a_text;
u_int32_t a_data;
u_int32_t a_bss;
u_int32_t a_syms;
u_int32_t a_entry;
u_int32_t a_trsize;
u_int32_t a_drsize;
};
.Ed
.Pp
The fields have the following functions:
.Bl -tag -width a_trsize
.It Fa a_midmag
This field is stored in network byte-order so that binaries for
machines with alternate byte orders can be distinguished.
It has a number of sub-components accessed by the macros
.Fn N_GETFLAG ,
.Fn N_GETMID ,
and
.Fn N_GETMAGIC ,
and set by the macro
.Fn N_SETMAGIC .
.Pp
The macro
.Fn N_GETFLAG
returns a few flags:
.Bl -tag -width EX_DYNAMIC
.It Dv EX_DYNAMIC
Indicates that the executable requires the services of the run-time link editor.
.It Dv EX_PIC
Indicates that the object contains position independent code.
This flag is set by
.Xr as 1
when given the
.Fl k
flag and is preserved by
.Xr ld 1
if necessary.
.El
.Pp
If both
.Dv EX_DYNAMIC
and
.Dv EX_PIC
are set, the object file is a position independent
executable image (e.g., a shared library), which is to be loaded into the
process address space by the run-time link editor.
.Pp
The macro
.Fn N_GETMID
returns the machine ID.
This indicates which machine(s) the binary is intended to run on.
.Pp
.Fn N_GETMAGIC
specifies the magic number, which uniquely identifies binary files
and distinguishes different loading conventions.
The field must contain one of the following values:
.Bl -tag -width ZMAGIC
.It Dv OMAGIC
The text and data segments immediately follow the header and are contiguous.
The kernel loads both text and data segments into writable memory.
.It Dv NMAGIC
As with
.Dv OMAGIC ,
text and data segments immediately follow the header and are contiguous.
However, the kernel loads the text into read-only memory and loads the data
into writable memory at the next page boundary after the text.
.It Dv ZMAGIC
The kernel loads individual pages on demand from the binary.
The header, text segment and data segment are all
padded by the link editor to a multiple of the page size.
Pages that the kernel loads from the text segment are read-only,
while pages from the data segment are writable.
.El
.It Fa a_text
Contains the size of the text segment in bytes.
.It Fa a_data
Contains the size of the data segment in bytes.
.It Fa a_bss
Contains the number of bytes in the
.Dq BSS segment
and is used by the kernel to set the initial break
.Pq Xr brk 2
after the data segment.
The kernel loads the program so that this amount of writable memory
appears to follow the data segment and initially reads as zeroes.
.It Fa a_syms
Contains the size in bytes of the symbol table section.
.It Fa a_entry
Contains the address in memory of the entry point
of the program after the kernel has loaded it;
the kernel starts the execution of the program
from the machine instruction at this address.
.It Fa a_trsize
Contains the size in bytes of the text relocation table.
.It Fa a_drsize
Contains the size in bytes of the data relocation table.
.El
.Pp
The
.Pa a.out.h
include file defines several macros which use an
.Fa exec
structure to test consistency or to locate section offsets in the binary file.
.Bl -tag -width N_TRELOFF(exec)
.It Fn N_BADMAG exec
Non-zero if the
.Fa a_magic
field does not contain a recognized value.
.It Fn N_TXTOFF exec
The byte offset of the beginning of the text segment.
.It Fn N_DATOFF exec
The byte offset of the beginning of the data segment.
.It Fn N_DRELOFF exec
The byte offset of the beginning of the data relocation table.
.It Fn N_TRELOFF exec
The byte offset of the beginning of the text relocation table.
.It Fn N_SYMOFF exec
The byte offset of the beginning of the symbol table.
.It Fn N_STROFF exec
The byte offset of the beginning of the string table.
.El
.Pp
Relocation records have a standard format which is described by the
.Fa relocation_info
structure:
.Bd -literal -offset indent
struct relocation_info {
int r_address;
unsigned int r_symbolnum : 24,
r_pcrel : 1,
r_length : 2,
r_extern : 1,
r_baserel : 1,
r_jmptable : 1,
r_relative : 1,
r_copy : 1;
};
.Ed
.Pp
The
.Fa relocation_info
fields are used as follows:
.Bl -tag -width r_symbolnum
.It Fa r_address
Contains the byte offset of a pointer that needs to be link-edited.
Text relocation offsets are reckoned from the start of the text segment,
and data relocation offsets from the start of the data segment.
The link editor adds the value that is already stored at this offset
into the new value that it computes using this relocation record.
.It Fa r_symbolnum
Contains the ordinal number of a symbol structure in the symbol table (it is
.Em not
a byte offset).
After the link editor resolves the absolute address for this symbol,
it adds that address to the pointer that is undergoing relocation.
(If the
.Fa r_extern
bit is clear, the situation is different; see below.)
.It Fa r_pcrel
If this is set, the link editor assumes that it is updating a pointer
that is part of a machine code instruction using pc-relative addressing.
The address of the relocated pointer is implicitly added
to its value when the running program uses it.
.It Fa r_length
Contains the log base 2 of the length of the pointer in bytes;
0 for 1-byte displacements, 1 for 2-byte displacements,
2 for 4-byte displacements.
.It Fa r_extern
Set if this relocation requires an external reference;
the link editor must use a symbol address to update the pointer.
When the
.Fa r_extern
bit is clear, the relocation is
.Dq local ;
the link editor updates the pointer to reflect
changes in the load addresses of the various segments,
rather than changes in the value of a symbol (except when
.Fa r_baserel
is also set, see below).
In this case, the content of the
.Fa r_symbolnum
field is an
.Fa n_type
value (see below);
this type field tells the link editor
what segment the relocated pointer points into.
.It Fa r_baserel
If set, the symbol, as identified by the
.Fa r_symbolnum
field, is to be relocated to an offset into the Global Offset Table.
At run-time, the entry in the Global Offset Table at this offset is set to
be the address of the symbol.
.It Fa r_jmptable
If set, the symbol, as identified by the
.Fa r_symbolnum
field, is to be relocated to an offset into the Procedure Linkage Table.
.It Fa r_relative
If set, this relocation is relative to the (run-time) load address of the
image this object file is going to be a part of.
This type of relocation only occurs in shared objects.
.It Fa r_copy
If set, this relocation record identifies a symbol whose contents should
be copied to the location given in
.Fa r_address .
The copying is done by the run-time link editor from a suitable data
item in a shared object.
.El
.Pp
Symbols map names to addresses (or more generally, strings to values).
Since the link editor adjusts addresses,
a symbol's name must be used to stand for its address
until an absolute value has been assigned.
Symbols consist of a fixed-length record in the symbol table
and a variable-length name in the string table.
The symbol table is an array of
.Fa nlist
structures:
.Bd -literal -offset indent
struct nlist {
union {
char *n_name;
long n_strx;
} n_un;
unsigned char n_type;
char n_other;
short n_desc;
unsigned long n_value;
};
.Ed
.Pp
The fields are used as follows:
.Bl -tag -width n_un.n_strx
.It Fa n_un.n_strx
Contains a byte offset into the string table for the name of this symbol.
When a program accesses a symbol table with the
.Xr nlist 3
function, this field is replaced with the
.Fa n_un.n_name
field, which is a pointer to the string in memory.
.It Fa n_type
Used by the link editor to determine how to update the symbol's value.
The
.Fa n_type
field is broken down into three sub-fields using bitmasks.
The link editor treats symbols with the
.Dv N_EXT
type bit set as
.Dq external
symbols and permits references to them from other binary files.
The
.Dv N_TYPE
mask selects bits of interest to the link editor:
.Bl -tag -width N_TEXT
.It Dv N_UNDF
An undefined symbol.
The link editor must locate an external symbol with the same name
in another binary file to determine the absolute value of this symbol.
As a special case, if the
.Fa n_value
field is non-zero and no binary file in the link-edit defines this symbol,
the link editor will resolve this symbol to an address
in the BSS segment, reserving an amount of bytes equal to
.Fa n_value .
If this symbol is undefined in more than one binary file
and the binary files do not agree on the size,
the link editor chooses the greatest size found across all binaries.
.It Dv N_ABS
An absolute symbol.
The link editor does not update an absolute symbol.
.It Dv N_TEXT
A text symbol.
This symbol's value is a text address and
the link editor will update it when it merges binary files.
.It Dv N_DATA
A data symbol; similar to
.Dv N_TEXT
but for data addresses.
The values for text and data symbols are not file offsets but
addresses; to recover the file offsets, it is necessary
to identify the loaded address of the beginning of the corresponding
section and subtract it, then add the offset of the section.
.It Dv N_BSS
A BSS symbol; like text or data symbols but
has no corresponding offset in the binary file.
.It Dv N_FN
A filename symbol.
The link editor inserts this symbol before
the other symbols from a binary file when
merging binary files.
The name of the symbol is the filename given to the link editor,
and its value is the first text address from that binary file.
Filename symbols are not needed for link editing or loading,
but are useful for debuggers.
.El
.Pp
The
.Dv N_STAB
mask selects bits of interest to symbolic debuggers
such as
.Xr gdb 1 ;
the values are described in
.Xr stab 5 .
.It Fa n_other
This field provides information on the nature of the symbol independent of
the symbol's location in terms of segments as determined by the
.Fa n_type
field.
Currently, the lower 4 bits of the
.Fa n_other
field hold one of two values:
.Dv AUX_FUNC
and
.Dv AUX_OBJECT
.Po
see
.Aq Pa link.h
for their definitions
.Pc .
.Dv AUX_FUNC
associates the symbol with a callable function, while
.Dv AUX_OBJECT
associates the symbol with data, irrespective of their locations in
either the text or the data segment.
This field is intended to be used by
.Xr ld 1
for the construction of dynamic executables.
.It Fa n_desc
Reserved for use by debuggers; passed untouched by the link editor.
Different debuggers use this field for different purposes.
.It Fa n_value
Contains the value of the symbol.
For text, data and BSS symbols, this is an address;
for other symbols (such as debugger symbols),
the value may be arbitrary.
.El
.Pp
The string table consists of an
.Em u_int32_t
length followed by null-terminated symbol strings.
The length represents the size of the entire table in bytes,
so its minimum value (or the offset of the first string)
is always 4 on 32-bit machines.
.Sh SEE ALSO
.Xr as 1 ,
.Xr gdb 1 ,
.Xr ld 1 ,
.Xr brk 2 ,
.Xr execve 2 ,
.Xr nlist 3 ,
.Xr core 5 ,
.Xr elf 5 ,
.Xr stab 5
.Sh HISTORY
The
.Pa a.out.h
include file appeared in
.At v3 .
.Sh BUGS
Nobody seems to agree on what
.Em BSS
stands for.

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: core.5,v 1.14 2012/08/30 15:57:13 deraadt Exp $
.\" $OpenBSD: core.5,v 1.15 2013/10/19 09:00:19 deraadt Exp $
.\" $NetBSD: core.5,v 1.4 1994/11/30 19:31:11 jtc Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
@ -30,7 +30,7 @@
.\"
.\" @(#)core.5 8.3 (Berkeley) 12/11/93
.\"
.Dd $Mdocdate: August 30 2012 $
.Dd $Mdocdate: October 19 2013 $
.Dt CORE 5
.Os
.Sh NAME
@ -144,10 +144,9 @@ struct core {
.Pp
The core structure's
.Fa c_midmag field
is an a.out midmag number with a
is an a.out-style midmag number with a
.Dv COREMAGIC
magic number (see
.Xr a.out 5 )
magic number.
and flags from the following list:
.Bd -unfilled -offset indent
#define CORE_CPU 1

View File

@ -1,224 +0,0 @@
.\" $OpenBSD: stab.5,v 1.14 2007/05/31 19:19:58 jmc Exp $
.\" $NetBSD: stab.5,v 1.3 1994/11/30 19:31:33 jtc Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" 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. Neither the name of the University 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 REGENTS 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 REGENTS 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.
.\"
.\" @(#)stab.5 8.1 (Berkeley) 6/5/93
.\"
.Dd $Mdocdate: May 31 2007 $
.Dt STAB 5
.Os
.Sh NAME
.Nm stab
.Nd symbol table types
.Sh SYNOPSIS
.Fd #include <stab.h>
.Sh DESCRIPTION
The
.Aq Pa stab.h
file defines some of the symbol table
.Fa n_type
field values for
.Xr a.out 5
files.
These are the types for permanent symbols (i.e., not local labels, etc.\&)
used by the old debugger
.Em sdb
and the Berkeley Pascal compiler pc.
.Pp
Symbol table entries can be produced by the
.Dq .stabs
assembler directive.
This allows one to specify a double-quote delimited name, a symbol type, one
.Li char
and one
.Li short
of information about the symbol, as well as an
.Li unsigned long
(usually an address).
.Pp
To avoid having to produce an explicit label for the address field,
the
.Dq .stabd
directive can be used to implicitly address the current location.
If no name is needed, symbol table entries can be generated using the
.Dq .stabn
directive.
The loader promises to preserve the order of symbol table entries produced by
.Dq .stab
directives.
As described in
.Xr a.out 5 ,
an element of the symbol table consists of the following structure:
.Bd -literal
/*
* Format of a symbol table entry.
*/
struct nlist {
union {
char *n_name; /* for use when in-core */
long n_strx; /* index into file string table */
} n_un;
unsigned char n_type; /* type flag */
char n_other; /* unused */
short n_desc; /* see struct desc, below */
unsigned n_value; /* address or offset or line */
};
.Ed
.Pp
The low bits of the
.Fa n_type
field are used to place a symbol into
at most one segment, according to
the following masks, defined in
.Aq Pa a.out.h .
A symbol can be in none of these segments by having none of these segment
bits set.
.Bd -literal
/*
* Simple values for n_type.
*/
#define N_UNDF 0x0 /* undefined */
#define N_ABS 0x2 /* absolute */
#define N_TEXT 0x4 /* text */
#define N_DATA 0x6 /* data */
#define N_BSS 0x8 /* bss */
#define N_EXT 01 /* external bit, or'ed in */
.Ed
.Pp
The
.Fa n_value
field of a symbol is relocated by the linker,
.Xr ld 1 ,
as an address within the appropriate segment.
.Fa n_value
fields of symbols not in any segment are unchanged by the linker.
In addition, the linker will discard certain symbols, according to rules
of its own, unless the
.Fa n_type
field has one of the following bits set:
.Bd -literal
/*
* Other permanent symbol table entries have some of the N_STAB bits set.
* These are given in <stab.h>
*/
#define N_STAB 0xe0 /* if any of these bits set, don't discard */
.Ed
.Pp
This allows up to 112 (7 \(** 16) symbol types, split between the various
segments.
Some of these have already been claimed.
The old symbolic debugger,
.Em sdb ,
uses the following
.Fa n_type
values:
.Bd -literal
#define N_GSYM 0x20 /* global symbol: name,,0,type,0 */
#define N_FNAME 0x22 /* procedure name (f77 kludge): name,,0 */
#define N_FUN 0x24 /* procedure: name,,0,linenumber,address */
#define N_STSYM 0x26 /* static symbol: name,,0,type,address */
#define N_LCSYM 0x28 /* .lcomm symbol: name,,0,type,address */
#define N_RSYM 0x40 /* register sym: name,,0,type,register */
#define N_SLINE 0x44 /* src line: 0,,0,linenumber,address */
#define N_SSYM 0x60 /* structure elt: name,,0,type,struct_offset */
#define N_SO 0x64 /* source file name: name,,0,0,address */
#define N_LSYM 0x80 /* local sym: name,,0,type,offset */
#define N_SOL 0x84 /* #included file name: name,,0,0,address */
#define N_PSYM 0xa0 /* parameter: name,,0,type,offset */
#define N_ENTRY 0xa4 /* alternate entry: name,linenumber,address */
#define N_LBRAC 0xc0 /* left bracket: 0,,0,nesting level,address */
#define N_RBRAC 0xe0 /* right bracket: 0,,0,nesting level,address */
#define N_BCOMM 0xe2 /* begin common: name,, */
#define N_ECOMM 0xe4 /* end common: name,, */
#define N_ECOML 0xe8 /* end common (local name): ,,address */
#define N_LENG 0xfe /* second stab entry with length information */
.Ed
.Pp
where the comments give
.Em sdb
conventional use for
.Dq .stab s
and the
.Fa n_name ,
.Fa n_other ,
.Fa n_desc ,
and
.Fa n_value
fields
of the given
.Fa n_type .
.Em sdb
uses the
.Fa n_desc
field to hold a type specifier in the form used
by the Portable C Compiler,
.Xr cc 1 ;
see the header file
.Pa pcc.h
for details on the format of these type values.
.Pp
The Berkeley Pascal compiler, pc, uses the following
.Fa n_type
value:
.Bd -literal
#define N_PC 0x30 /* global pascal symbol: name,,0,subtype,line */
.Ed
.Pp
and uses the following subtypes to do type checking across separately
compiled files:
.Bd -unfilled -offset indent
1 source file name
2 included file name
3 global label
4 global constant
5 global type
6 global variable
7 global function
8 global procedure
9 external function
10 external procedure
11 library variable
12 library routine
.Ed
.Sh SEE ALSO
.Xr as 1 ,
.Xr gdb 1 ,
.Xr ld 1 ,
.Xr a.out 5
.Sh HISTORY
The
.Nm
file appeared in
.Bx 4.0 .
.Sh BUGS
More basic types are needed.