PERFORCE change 104290 for review
John Birrell
jb at FreeBSD.org
Wed Aug 16 20:37:56 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=104290
Change 104290 by jb at jb_freebsd2 on 2006/08/16 20:37:27
IFlibbsdelf (a.k.a. two steps forward, one step back)
Affected files ...
.. //depot/projects/dtrace/src/lib/libelf/Makefile#7 integrate
.. //depot/projects/dtrace/src/lib/libelf/_libelf.h#4 integrate
.. //depot/projects/dtrace/src/lib/libelf/elf_allocate.c#5 delete
.. //depot/projects/dtrace/src/lib/libelf/elf_errmsg.c#4 integrate
.. //depot/projects/dtrace/src/lib/libelf/elf_memory.c#3 integrate
.. //depot/projects/dtrace/src/lib/libelf/gelf_ehdr.c#1 branch
.. //depot/projects/dtrace/src/lib/libelf/gelf_getehdr.3#2 integrate
.. //depot/projects/dtrace/src/lib/libelf/gelf_getehdr.c#3 delete
.. //depot/projects/dtrace/src/lib/libelf/gelf_newehdr.3#2 integrate
.. //depot/projects/dtrace/src/lib/libelf/gelf_newehdr.c#2 delete
.. //depot/projects/dtrace/src/lib/libelf/libelf.c#2 integrate
.. //depot/projects/dtrace/src/lib/libelf/libelf.h#4 integrate
.. //depot/projects/dtrace/src/lib/libelf/libelf_allocate.c#1 branch
.. //depot/projects/dtrace/src/lib/libelf/libelf_ar.c#1 branch
.. //depot/projects/dtrace/src/lib/libelf/libelf_ehdr.c#1 branch
Differences ...
==== //depot/projects/dtrace/src/lib/libelf/Makefile#7 (text+ko) ====
@@ -2,8 +2,7 @@
LIB= elf
-SRCS= elf_allocate.c \
- elf_begin.c \
+SRCS= elf_begin.c \
elf_cntl.c \
elf_dump.c \
elf_dump_argv.c \
@@ -31,7 +30,7 @@
elf_version.c \
gelf_fsize.c \
gelf_getclass.c \
- gelf_getehdr.c \
+ gelf_ehdr.c \
gelf_getphdr.c \
gelf_getshdr.c \
gelf_getsym.c \
@@ -42,7 +41,10 @@
gelf_update_shdr.c \
gelf_update_sym.c \
gelf_xlate.c \
- libelf.c
+ libelf.c \
+ libelf_allocate.c \
+ libelf_ar.c \
+ libelf_ehdr.c
INCS= libelf.h gelf.h
DPSRCS+= libelf_fsize.c libelf_msize.c libelf_convert.c
@@ -97,8 +99,13 @@
gelf_xlatetof.3 gelf_xlatetom.3
MLINKS+= \
- gelf_fsize.3 elf32_fsize.3 \
- gelf_fsize.3 elf64_fsize.3
+ gelf_fsize.3 elf32_fsize.3 \
+ gelf_fsize.3 elf64_fsize.3 \
+ gelf_getehdr.3 elf32_getehdr.3 \
+ gelf_getehdr.3 elf64_getehdr.3 \
+ gelf_newehdr.3 elf32_newehdr.3 \
+ gelf_newehdr.3 elf64_newehdr.3
+
MLINKS+= \
elf_flagdata.3 elf_flagehdr.3 \
==== //depot/projects/dtrace/src/lib/libelf/_libelf.h#4 (text+ko) ====
@@ -42,6 +42,7 @@
#define LIBELF_MSG_SIZE 256
struct _libelf_globals {
+ int libelf_arch;
unsigned int libelf_byteorder;
int libelf_class;
int libelf_error;
@@ -62,6 +63,8 @@
((O) << LIBELF_OS_ERROR_SHIFT)); \
} while (0)
+#define LIBELF_ADJUST_AR_SIZE(S) (((S) + 1) & ~1)
+
/*
* Flags for library internal use. These use the upper 16 bits of a
* flags field.
@@ -72,7 +75,7 @@
struct _Elf {
int e_activations; /* activation count */
- int e_byteorder; /* ELFDATA* */
+ unsigned int e_byteorder; /* ELFDATA* */
int e_class; /* ELFCLASS* */
Elf_Cmd e_cmd; /* ELF_C_* used at creation time */
int e_fd; /* associated file descriptor */
@@ -99,14 +102,20 @@
struct { /* ar(1) archives */
off_t e_next;
int e_nchildren;
+ char *e_rawstrtab; /* file name strings */
+ size_t e_rawstrtabsz;
+ char *e_rawsymtab; /* symbol table */
+ size_t e_rawsymtabsz;
+ Elf_Arhdr *e_hdrtab;
+ Elf_Arsym *e_symtab;
} e_ar;
struct { /* regular ELF files */
+ union {
+ Elf32_Ehdr *e_ehdr32;
+ Elf64_Ehdr *e_ehdr64;
+ } e_ehdr;
} e_elf;
} e_u;
- struct { /* archive members */
- LIST_ENTRY(_Elf) e_sibling; /* sibling */
- } e_mem;
-
};
enum {
@@ -123,11 +132,12 @@
unsigned int _flags);
int _libelf_dump64(Elf *_elf, const char *_name, const char *_outfile,
unsigned int _flags);
-void *libelf_ehdr(Elf *_e, int _elfclass, int _allocate);
+void *_libelf_ehdr(Elf *_e, int _elfclass, int _allocate);
void (*_libelf_get_translator(Elf_Type _t, int _direction, int _elfclass))
(char *_dst, char *_src, int _cnt, int _byteswap);
int _libelf_malign(Elf_Type _t, int _elfclass);
size_t _libelf_msize(Elf_Type _t, int _elfclass, unsigned int _version);
+Elf *_libelf_ar_open(Elf *_e);
void _libelf_release_elf(Elf *_e);
#endif /* __LIBELF_H_ */
==== //depot/projects/dtrace/src/lib/libelf/elf_errmsg.c#4 (text+ko) ====
@@ -41,7 +41,7 @@
DEFINE_ERROR(NONE, "No Error"),
DEFINE_ERROR(ARCHIVE, "Malformed ar(1) archive"),
DEFINE_ERROR(ARGUMENT, "Invalid argument"),
- DEFINE_ERROR(HEADER, "Missing ELF header"),
+ DEFINE_ERROR(HEADER, "Missing or malformed ELF header"),
DEFINE_ERROR(CLASS, "ELF class mismatch"),
DEFINE_ERROR(MMAP, "File mapping failed"),
DEFINE_ERROR(MODE, "Incorrect ELF descriptor mode"),
==== //depot/projects/dtrace/src/lib/libelf/elf_memory.c#3 (text+ko) ====
@@ -55,6 +55,10 @@
return (NULL);
}
+ e->e_cmd = ELF_C_READ;
+ e->e_rawfile = image;
+ e->e_rawsize = sz;
+
#undef LIBELF_IS_ELF
#define LIBELF_IS_ELF(P) ((P)[EI_MAG0] == ELFMAG0 && \
(P)[EI_MAG1] == ELFMAG1 && (P)[EI_MAG2] == ELFMAG2 && \
@@ -71,17 +75,11 @@
LIBELF_SET_ERROR(VERSION, 0);
return (NULL);
}
- } else if (sz >= SARMAG && strncmp(image, ARMAG, SARMAG) == 0) {
- e->e_kind = ELF_K_AR;
- e->e_u.e_ar.e_nchildren = 0;
- e->e_u.e_ar.e_next = (off_t) -1; /* XXX set to first element */
- } else
+ } else if (sz >= SARMAG && strncmp(image, ARMAG, SARMAG) == 0)
+ e = _libelf_ar_open(e);
+ else
e->e_kind = ELF_K_NONE;
- e->e_cmd = ELF_C_READ;
- e->e_rawfile = image;
- e->e_rawsize = sz;
-
if (e->e_kind == ELF_K_ELF) {
src.d_buf = image;
src.d_off = 0;
==== //depot/projects/dtrace/src/lib/libelf/gelf_getehdr.3#2 (text+ko) ====
@@ -46,32 +46,18 @@
These functions retrieve the ELF object file
header from the ELF descriptor
.Ar elf
-and return a translated header descriptor structure to their caller.
-.Pp
-The semantics of translation between file data structures and memory
-data structures is described in
-.Xr elf 3 .
-The semantics of translation between class-independent representations
-and class-dependent representations is described in
-.Xr gelf 3 .
-The
-.Vt Elf32_Ehdr
-and
-.Vt Elf64_Ehdr
-header descriptors are described in
-.Xr elf 5 .
-The
-.Vt Gelf_Ehdr
-descriptor is described in
-.Xr gelf 3 .
+and return a translated header descriptor to their callers.
.Pp
Functions
.Fn elf32_getehdr
and
.Fn elf64_getehdr
-return a pointer to the appropriate class-specific header descriptor if it exists, or
+return a pointer to the appropriate class-specific header descriptor
+if it exists in the file referenced by descriptor
+.Ar elf .
+These functions return
.Dv NULL
-if no header exists for ELF descriptor
+if an ELF header was not found in file
.Ar elf .
.Pp
Function
@@ -100,6 +86,10 @@
.Ar elf
was not a descriptor for an ELF file.
.It Bq Er ELF_E_ARGUMENT
+The elf class of descriptor
+.Ar elf
+was not recognized.
+.It Bq Er ELF_E_ARGUMENT
Argument
.Ar dst
was null.
==== //depot/projects/dtrace/src/lib/libelf/gelf_newehdr.3#2 (text+ko) ====
@@ -30,7 +30,7 @@
.Nm elf32_newehdr
.Nm elf64_newehdr
.Nm gelf_newehdr
-.Nd retrieve the object file header
+.Nd retrieve or allocate the object file header
.Sh LIBRARY
.Lb libelf
.Sh SYNOPSIS
@@ -43,52 +43,78 @@
.Ft "void *"
.Fn gelf_newehdr "Elf *elf" "int elfclass"
.Sh DESCRIPTION
-These functions retrieve the ELF object file
-header from the ELF descriptor
+These functions retrieve the ELF header from the ELF descriptor
.Ar elf ,
allocating a new header if needed.
-.Pp
-The semantics of translation between file data structures and memory
-data structures is described in
+File data structures are translated to their in-memory representations
+as described in
.Xr elf 3 .
-The
-.Vt Elf32_Ehdr
-and
-.Vt Elf64_Ehdr
-header descriptors are described in
-.Xr elf 5 .
.Pp
-Functions
+Function
.Fn elf32_newehdr
-and
+returns a pointer to a 32 bit
+.Vt Elf32_Ehdr
+structure.
+Function
.Fn elf64_newehdr
-return a pointer to a 32 bit and 64 bit class-specific header
-descriptor respectively.
+returns a pointer to a 64 bit
+.Vt Elf64_Ehdr structure.
.Pp
-Function
-.Fn gelf_newehdr
-returns the value returned by
-.Fn elf32_newehdr "elf"
-when argument
+When argument
.Ar elfclass
has value
.Dv ELFCLASS32 ,
-and returns the value returned by
-.Fn elf64_newehdr "elf"
-when argument
+function
+.Fn gelf_newehdr
+returns the value returned by
+.Fn elf32_newehdr "elf" .
+When argument
.Ar elfclass
has value
-.Dv ELFCLASS64 .
-Its return value is of type
-.Ft "Elf32_Ehdr *"
-or
-.Ft "Elf64_Ehdr *"
-depending on the value of argument
-.Ar elfclass .
+.Dv ELFCLASS64
+it returns the value returned by
+.Fn elf64_newehdr "elf" .
+.Pp
+If a fresh header structure is allocated, the following members of the
+structure will be set to zero except the following:
+.Bl -tag -width indent
+.It Va e_ident
+Identification bytes at offsets
+.Dv EI_MAG0 ,
+.Dv EI_MAG1 ,
+.Dv EI_MAG2
+and
+.Dv EI_MAG3
+are set to the ELF signature.
+The byte at offset
+.Dv EI_CLASS
+is set to the default ELF class for the host,
+the byte at offset
+.Dv EI_DATA
+is set to
+.Dv ELFDATANONE ,
+and byte at offset
+.Dv EI_VERSION
+is set to
+.Dv EV_NONE .
+.It Va e_machine
+is set to
+.Dv EM_NONE .
+.It Va e_type
+is set to
+.Dv ELF_K_ELF .
+.It Va e_version
+is set to
+.Dv EV_NONE .
+.El
+.Pp
+The application is responsible for changing these values
+as needed before calling
+.Fn elf_update .
.Pp
If successful, these three functions set the
.Dv ELF_F_DIRTY
-bit on ELF executable
+bit on ELF descriptor
.Ar elf .
.Sh RETURN VALUES
These functions return a pointer to a translated header descriptor
@@ -103,7 +129,7 @@
.It Bq Er ELF_E_ARGUMENT
Argument
.Ar elf
-was not a descriptor for an ELF file.
+was not a descriptor for an ELF object.
.It Bq Er ELF_E_ARGUMENT
Argument
.Ar elfclass
@@ -111,9 +137,18 @@
.It Bq Er ELF_E_ARGUMENT
The class of the ELF descriptor
.Ar elf
-was set previously, and argument
-.Ar elfclass
-did not match its class.
+did not match that of the requested operation.
+.It Bq Er ELF_E_ARGUMENT
+For function
+.Fn gelf_newehdr ,
+the class of argument
+.Ar elf
+was not
+.Dv ELFCLASSNONE
+and did not match the argument
+.Ar elfclass .
+.It Bq Er ELF_E_HEADER
+A malformed ELF header was detected.
.It Bq Er ELF_E_RESOURCE
An out of memory condition was detected during execution.
.El
@@ -121,8 +156,10 @@
.Xr elf 3 ,
.Xr elf_flagdata 3 ,
.Xr elf_getident 3 ,
+.Xr elf_update 3 ,
.Xr elf32_getehdr 3 ,
.Xr elf64_getehdr 3 ,
+.Xr elf_version 3 ,
.Xr gelf 3 ,
.Xr gelf_getehdr 3 ,
.Xr elf 5
==== //depot/projects/dtrace/src/lib/libelf/libelf.c#2 (text+ko) ====
@@ -37,11 +37,12 @@
#include "_libelf.h"
struct _libelf_globals _libelf = {
- .libelf_byteorder = ELF_TARG_DATA,
- .libelf_class = ELF_TARG_CLASS,
- .libelf_error = 0,
- .libelf_fillchar = 0,
- .libelf_version = EV_NONE
+ .libelf_arch = ELF_ARCH,
+ .libelf_byteorder = ELF_TARG_DATA,
+ .libelf_class = ELF_TARG_CLASS,
+ .libelf_error = 0,
+ .libelf_fillchar = 0,
+ .libelf_version = EV_NONE
};
==== //depot/projects/dtrace/src/lib/libelf/libelf.h#4 (text+ko) ====
@@ -141,7 +141,7 @@
ELF_E_ARCHIVE, /* Malformed ar(1) archive */
ELF_E_ARGUMENT, /* Invalid argument */
ELF_E_CLASS, /* ELF class mismatch */
- ELF_E_HEADER, /* Missing ELF header */
+ ELF_E_HEADER, /* Missing or malformed ELF header */
ELF_E_MMAP, /* File mapping failed */
ELF_E_MODE, /* Wrong mode for ELF descriptor */
ELF_E_RESOURCE, /* Resource exhaustion */
More information about the p4-projects
mailing list