elftoolchain: Be consistent about which ELF header files we use.
1. For tools that use elftoolchain: always use elftoolchain's elfdefinitions.h. Don't even think about looking at the host's sys/exec_elf.h, which makes no sense and should never happen. (ELF tools that don't use elftoolchain, like m68k-elf2coff, continue to use nbincludes/sys/exec_elf.h. But no more nbincludes hacks in elftoolchain.) 2. For kernel components (solaris, zfs, dtrace): always use sys/exec_elf.h, even in Solaris components via sys/elf.h. elfdefinitions.h is not wired up in the kernel build at all. 3. For most userland components that involve libelf: use elfdefinitions.h via libelf header files (libelf.h, gelf.h). libdtrace in particular requires _all_ R_* reloc type definitions, but sys/exec_elf.h brings in only the _current machine's_ R_* reloc type definitions. (While here: Use uintptr_t instead of Elf_Addr for pointer-to-integer cast, since Elf_Addr is MD and provided only by sys/exec_elf.h, not by elfdefinitions.h.) And most userland components using libelf don't rely on any properties of the current machine from sys/exec_elf.h, so they can use libelf's elfdefinition.h. Exceptions: - dtrace drti.c relies on link.h -> link_elf.h -> sys/exec_elf.h, but it also relies on sys/dtrace.h -> sys/elf.h -> elfdefinitions.h like other userland components using sys/elf.h. - kdump-ioctl.c uses sys/exec_elf.h directly and sys/dtrace.h -> sys/elf.h -> elfdefinitions like other userland components using sys/elf.h. - t_ptrace_wait.c (via t_ptrace_core_wait.h) uses libelf to parse core files, but relies on sys/exec_elf.h for struct netbsd_elfcore_procinfo. None of these exceptions needs all R_* reloc type definitions, so as a workaround, we can just suppress libelf's elfdefinitions.h by defining _SYS_ELFDEFINITIONS_H_ and use sys/exec_elf.h in these exceptions. And undo the whole BUILTIN_ELF_HEADERS mistake. This was: - half bogus workarounds for missing build_install dependencies in tools/Makefile, which are no longer missing now, and - half futile attempt to use src/sys/sys/exec_elf.h via nbincludes in tools involving libelf instead of libelf's elfdefinitions.h, which collides. Longer-term, we may wish to unify sys/exec_elf.h and libelf's elfdefinitions.h, so we don't have to play these games. But at least now the games are limited to three .c files (one of which is generated by Makefile.ioctl-c), rather than haphazardly applied tree-wide by monstrous kludges in widely used .h files with broken hackarounds to get the tools build lurching to completion.
This commit is contained in:
parent
9dafaafcc9
commit
ad49149131
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: _libelf_config.h,v 1.6 2024/03/03 17:37:33 christos Exp $ */
|
||||
/* $NetBSD: _libelf_config.h,v 1.7 2024/04/01 18:33:22 riastradh Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008-2011 Joseph Koshy
|
||||
|
@ -28,28 +28,6 @@
|
|||
* Id: _libelf_config.h 3975 2022-04-30 20:10:58Z jkoshy
|
||||
*/
|
||||
|
||||
#if defined(__NetBSD__) || defined(HAVE_NBTOOL_CONFIG_H)
|
||||
|
||||
#include <machine/elf_machdep.h>
|
||||
|
||||
#if !defined(ARCH_ELFSIZE)
|
||||
#error ARCH_ELFSIZE is not defined.
|
||||
#endif
|
||||
|
||||
#if ARCH_ELFSIZE == 32
|
||||
#define LIBELF_ARCH ELF32_MACHDEP_ID
|
||||
#define LIBELF_BYTEORDER ELF32_MACHDEP_ENDIANNESS
|
||||
#define LIBELF_CLASS ELFCLASS32
|
||||
#define Elf_Note Elf32_Nhdr
|
||||
#else
|
||||
#define LIBELF_ARCH ELF64_MACHDEP_ID
|
||||
#define LIBELF_BYTEORDER ELF64_MACHDEP_ENDIANNESS
|
||||
#define LIBELF_CLASS ELFCLASS64
|
||||
#define Elf_Note Elf64_Nhdr
|
||||
#endif
|
||||
|
||||
#endif /* __NetBSD__ || HAVE_NBTOOL_CONFIG_H */
|
||||
|
||||
/*
|
||||
* Downstream projects can replace the following placeholder with a custom
|
||||
* definition of LIBELF_BYTEORDER, if the host's native byte order cannot
|
||||
|
@ -57,7 +35,6 @@
|
|||
*/
|
||||
/* @LIBELF-DEFINE-HOST-BYTEORDER@ */
|
||||
|
||||
#ifndef HAVE_NBTOOL_CONFIG_H
|
||||
#if !defined(LIBELF_BYTEORDER)
|
||||
|
||||
/*
|
||||
|
@ -79,4 +56,3 @@
|
|||
|
||||
#endif /* defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) */
|
||||
#endif /* !defined(LIBELF_BYTEORDER) */
|
||||
#endif /* HAVE_NBTOOL_CONFIG_H */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: libelf.h,v 1.6 2024/03/03 17:37:34 christos Exp $ */
|
||||
/* $NetBSD: libelf.h,v 1.7 2024/04/01 18:33:22 riastradh Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006,2008-2010 Joseph Koshy
|
||||
|
@ -33,26 +33,12 @@
|
|||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
# include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef BUILTIN_ELF_HEADERS
|
||||
# include <sys/types.h>
|
||||
# include <stdint.h>
|
||||
# include "elfdefinitions.h"
|
||||
#elif HAVE_NBTOOL_CONFIG_H
|
||||
# include <nbinclude/sys/exec_elf.h>
|
||||
#elif defined(__NetBSD__)
|
||||
# include <sys/types.h>
|
||||
# include <sys/exec_elf.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
# include <sys/types.h>
|
||||
# include <sys/elf32.h>
|
||||
# include <sys/elf64.h>
|
||||
#else
|
||||
#error "No valid elf headers"
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include "elfdefinitions.h"
|
||||
|
||||
/* Library private data structures */
|
||||
typedef struct _Elf Elf;
|
||||
typedef struct _Elf_Scn Elf_Scn;
|
||||
|
|
|
@ -82,7 +82,6 @@ GENSRCS= dwarf_pubnames.c dwarf_pubtypes.c dwarf_weaks.c \
|
|||
dwarf_pro_funcs.c dwarf_pro_types.c \
|
||||
dwarf_pro_vars.c
|
||||
CLEANFILES= ${GENSRCS}
|
||||
CPPFLAGS+= -DBUILTIN_ELF_HEADERS
|
||||
CPPFLAGS+= -I. -I${SRCDIR} -I${TOP}/common -I${TOP}/libelf
|
||||
|
||||
LIBDPLIBS+= elf ${.CURDIR}/../libelf
|
||||
|
|
|
@ -24,6 +24,25 @@
|
|||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
/*
|
||||
* XXX Hack: Force the use of sys/exec_elf.h, not elfdefinitions.h.
|
||||
* Why?
|
||||
*
|
||||
* - sys/dtrace.h is needed because (XXX why?).
|
||||
* => sys/dtrace.h pulls in sys/ctf_api.h
|
||||
* => which pulls in sys/elf.h
|
||||
* => which pulls in elfdefinitions.h (XXX should it?)
|
||||
*
|
||||
* - link.h is needed for Link_map.
|
||||
* => link.h pulls in link_elf.h
|
||||
* => which pulls in sys/exec_elf.h
|
||||
*
|
||||
* But elfdefinitions.h and sys/exec_elf.h collide over most basic ELF
|
||||
* definitions. Since we don't need elfdefinitions.h otherwise, prefer
|
||||
* sys/exec_elf.h.
|
||||
*/
|
||||
#define _SYS_ELFDEFINITIONS_H_
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <dlfcn.h>
|
||||
|
|
|
@ -125,7 +125,7 @@ dt_module_syminit32(dt_module_t *dmp)
|
|||
dmp->dm_sec_offsets[sym->st_shndx];
|
||||
#endif
|
||||
#ifdef __NetBSD__
|
||||
sym->st_value += (Elf_Addr) dmp->dm_reloc_offset;
|
||||
sym->st_value += (uintptr_t) dmp->dm_reloc_offset;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ dt_module_syminit64(dt_module_t *dmp)
|
|||
dmp->dm_sec_offsets[sym->st_shndx];
|
||||
#endif
|
||||
#ifdef __NetBSD__
|
||||
sym->st_value += (Elf_Addr) dmp->dm_reloc_offset;
|
||||
sym->st_value += (uintptr_t) dmp->dm_reloc_offset;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: elf.h,v 1.1 2010/02/21 01:46:35 darran Exp $ */
|
||||
/* $NetBSD: elf.h,v 1.2 2024/04/01 18:33:23 riastradh Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009 The NetBSD Foundation, Inc.
|
||||
|
@ -30,9 +30,11 @@
|
|||
#define _ELF_H_
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include <nbinclude/sys/exec_elf.h>
|
||||
# include "nbtool_config.h"
|
||||
#else
|
||||
#include <sys/exec_elf.h>
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include "elfdefinitions.h"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: elf.h,v 1.6 2018/05/28 21:05:10 chs Exp $ */
|
||||
/* $NetBSD: elf.h,v 1.7 2024/04/01 18:33:23 riastradh Exp $ */
|
||||
|
||||
/*
|
||||
* CDDL HEADER START
|
||||
|
@ -30,12 +30,25 @@
|
|||
#define _SYS__ELF_SOLARIS_H_
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include <nbinclude/sys/exec_elf.h>
|
||||
# include "nbtool_config.h"
|
||||
#else
|
||||
#include <sys/exec_elf.h>
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* XXX In the kernel (e.g., zfs module build, or anything else using
|
||||
* sys/dtrace.h -> sys/ctf_api.h -> sys/elf.h), sys/elfdefinitions.h
|
||||
* isn't available -- it's a header file for the userland libelf. We
|
||||
* could maybe make it available, but sys/exec_elf.h -- which would
|
||||
* collide with sys/elfdefinitions.h -- provides all the definitions
|
||||
* users need, so we'll just use that for now.
|
||||
*/
|
||||
#ifdef _KERNEL
|
||||
# include <sys/exec_elf.h>
|
||||
#else
|
||||
# include <sys/elfdefinitions.h>
|
||||
#endif
|
||||
|
||||
#define SHT_SUNW_dof 0x6ffffff4
|
||||
#define EM_AMD64 EM_X86_64
|
||||
|
||||
#define __ELF_WORD_SIZE ELFSIZE
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: t_ptrace_wait.c,v 1.191 2020/05/05 02:06:08 kamil Exp $ */
|
||||
/* $NetBSD: t_ptrace_wait.c,v 1.192 2024/04/01 18:33:23 riastradh Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2016, 2017, 2018, 2019, 2020 The NetBSD Foundation, Inc.
|
||||
|
@ -26,8 +26,23 @@
|
|||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* XXX Hack: Force the use of sys/exec_elf.h, not elfdefinitions.h.
|
||||
* Why?
|
||||
*
|
||||
* - libelf.h and gelf.h are needed for parsing core files in
|
||||
* t_ptrace_core_wait.h.
|
||||
*
|
||||
* - sys/exec_elf.h is needed for struct netbsd_elfcore_procinfo also
|
||||
* in t_ptrace_core_wait.h.
|
||||
*
|
||||
* libelf.h and gelf.h pull in elfdefinitions.h, but that conflicts
|
||||
* with sys/exec_elf.h on most basic ELF definitions.
|
||||
*/
|
||||
#define _SYS_ELFDEFINITIONS_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: t_ptrace_wait.c,v 1.191 2020/05/05 02:06:08 kamil Exp $");
|
||||
__RCSID("$NetBSD: t_ptrace_wait.c,v 1.192 2024/04/01 18:33:23 riastradh Exp $");
|
||||
|
||||
#define __LEGACY_PT_LWPINFO
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile,v 1.10 2022/04/18 19:40:06 jkoshy Exp $
|
||||
# $NetBSD: Makefile,v 1.11 2024/04/01 18:33:23 riastradh Exp $
|
||||
|
||||
.include <bsd.hostinit.mk>
|
||||
|
||||
|
@ -37,7 +37,8 @@ HOST_CPPFLAGS+= -I${OSNETDIR}/sys \
|
|||
-I${OPENSOLARIS_DISTDIR}/tools/ctf/cvt \
|
||||
-I${OPENSOLARIS_DISTDIR}/uts/common \
|
||||
-I${LIBELF_DIR} \
|
||||
-I${LIBDWARF_DIR}
|
||||
-I${LIBDWARF_DIR} \
|
||||
-I${TOOLDIR}/include
|
||||
|
||||
HOST_CPPFLAGS+= -DHAVE_NBTOOL_CONFIG_H=1
|
||||
|
||||
|
@ -57,5 +58,4 @@ DPADD+= ${ELFOBJ}/libelf.a
|
|||
.PATH: ${OPENSOLARIS_DISTDIR}/tools/ctf/common
|
||||
.PATH: ${OPENSOLARIS_DISTDIR}/tools/ctf/cvt
|
||||
|
||||
.include "${.CURDIR}/../Makefile.nbincludes"
|
||||
.include "${.CURDIR}/../Makefile.host"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile,v 1.11 2022/04/18 19:40:06 jkoshy Exp $
|
||||
# $NetBSD: Makefile,v 1.12 2024/04/01 18:33:23 riastradh Exp $
|
||||
|
||||
.include <bsd.hostinit.mk>
|
||||
|
||||
|
@ -17,7 +17,8 @@ HOST_CPPFLAGS+= -I${OSNETDIR}/sys \
|
|||
-I${OPENSOLARIS_DISTDIR}/tools/ctf/cvt \
|
||||
-I${OPENSOLARIS_DISTDIR}/uts/common \
|
||||
-I${LIBELF_DIR} \
|
||||
-I${LIBDWARF_DIR}
|
||||
-I${LIBDWARF_DIR} \
|
||||
-I${TOOLDIR}/include
|
||||
|
||||
HOST_CPPFLAGS+= -DHAVE_NBTOOL_CONFIG_H=1
|
||||
|
||||
|
@ -37,5 +38,4 @@ HOST_CFLAGS+= -pthread
|
|||
.PATH: ${OPENSOLARIS_DISTDIR}/tools/ctf/common
|
||||
.PATH: ${OPENSOLARIS_DISTDIR}/tools/ctf/cvt
|
||||
|
||||
.include "${.CURDIR}/../Makefile.nbincludes"
|
||||
.include "${.CURDIR}/../Makefile.host"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile,v 1.6 2024/03/30 22:39:53 riastradh Exp $
|
||||
# $NetBSD: Makefile,v 1.7 2024/04/01 18:33:23 riastradh Exp $
|
||||
|
||||
HOSTLIB=dwarf
|
||||
|
||||
|
@ -73,12 +73,11 @@ COMPATLIB_NO_LIB= yes # only the include files, not the library
|
|||
|
||||
LIBDWARF_OBJDIR!= cd ${.CURDIR} && ${PRINTOBJDIR}
|
||||
|
||||
CPPFLAGS+= -DBUILTIN_ELF_HEADERS
|
||||
CPPFLAGS+= -I${.CURDIR}/../../compat
|
||||
CPPFLAGS+= -I${.CURDIR}/../../common
|
||||
CPPFLAGS+= -I${LIBDWARF_OBJDIR}/../common
|
||||
CPPFLAGS+= -I${LIBDWARF_DIR} -I${LIBELF_DIR} -I${COMMON_DIR}
|
||||
CPPFLAGS+= -I${TOOLDIR}/include -I${TOOLDIR}/include/nbinclude
|
||||
CPPFLAGS+= -I${TOOLDIR}/include
|
||||
|
||||
BUILD_OSTYPE!= uname -s
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile,v 1.2 2024/03/03 17:37:58 christos Exp $
|
||||
# $NetBSD: Makefile,v 1.3 2024/04/01 18:33:24 riastradh Exp $
|
||||
|
||||
HOSTLIB= elf
|
||||
|
||||
|
@ -54,7 +54,7 @@ CLEANFILES+= ${LIBELF_GENSRCS}
|
|||
CPPFLAGS+= -I${.CURDIR}/../../compat
|
||||
CPPFLAGS+= -I${LIBELF_DIR} -I${LIBELF_DIR}/../common
|
||||
CPPFLAGS+= -I${LIBELF_OBJDIR}/../common
|
||||
CPPFLAGS+= -I${TOOLDIR}/include -I${TOOLDIR}/include/nbinclude
|
||||
CPPFLAGS+= -I${TOOLDIR}/include
|
||||
|
||||
CPPFLAGS+= -DLIBELF_TEST_HOOKS
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile,v 1.9 2022/05/03 10:50:42 jkoshy Exp $
|
||||
# $NetBSD: Makefile,v 1.10 2024/04/01 18:33:24 riastradh Exp $
|
||||
|
||||
HOSTLIB= ctf
|
||||
|
||||
|
@ -62,5 +62,4 @@ ${TOOLDIR}/lib/libctf.a:: libctf.a
|
|||
mkdir -p ${TOOLDIR}/lib
|
||||
${HOST_INSTALL_FILE} -m ${BINMODE} libctf.a ${.TARGET}
|
||||
|
||||
.include "${.CURDIR}/../Makefile.nbincludes"
|
||||
.include <bsd.hostlib.mk>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile.ioctl-c,v 1.39 2022/11/12 02:20:16 mrg Exp $
|
||||
# $NetBSD: Makefile.ioctl-c,v 1.40 2024/04/01 18:33:24 riastradh Exp $
|
||||
|
||||
# NOTE: <bsd.own.mk> needs to be previously .included for NETBSDSRCDIR
|
||||
|
||||
|
@ -63,6 +63,7 @@ CPPFLAGS+= -D__SAVAGE_DRM_H__ # Dup ioctls
|
|||
#CPPFLAGS+= -D__RADEON_DRM_H__ # Dup ioctls
|
||||
CPPFLAGS+= -D__MACH64_DRM_H__ # Dup ioctls
|
||||
CPPFLAGS+= -D__MGA_DRM_H__ # Dup ioctls
|
||||
CPPFLAGS+= -D_SYS_ELFDEFINITIONS_H_ # collides with sys/exec_elf.h
|
||||
|
||||
${PROG}-ioctl.c: mkioctls Makefile ${DEPFILES} ${SETFILES}
|
||||
${_MKTARGET_CREATE}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ksyms.c,v 1.2 2022/12/01 00:43:27 ryo Exp $ */
|
||||
/* $NetBSD: ksyms.c,v 1.3 2024/04/01 18:33:24 riastradh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010,2011,2012 YAMAMOTO Takashi,
|
||||
|
@ -28,7 +28,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: ksyms.c,v 1.2 2022/12/01 00:43:27 ryo Exp $");
|
||||
__RCSID("$NetBSD: ksyms.c,v 1.3 2024/04/01 18:33:24 riastradh Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -118,7 +118,7 @@ ksymload(size_t *nsymp)
|
|||
if (st == NULL) {
|
||||
goto elffail;
|
||||
}
|
||||
if (ELF_ST_TYPE(st->st_info) != STT_FUNC) {
|
||||
if (GELF_ST_TYPE(st->st_info) != STT_FUNC) {
|
||||
continue;
|
||||
}
|
||||
sym = emalloc(sizeof(*sym));
|
||||
|
|
Loading…
Reference in New Issue