Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
ABI: get rid of altabi
Baptiste Daroussin committed 1 year ago
commit c2fe22b4f51bdd14763555ed273047c66878de5b
parent 74c2b62
5 files changed +25 -251
modified libpkg/pkg_abi.c
@@ -135,40 +135,16 @@ pkg_get_myarch_with_legacy(struct os_info *oi)
		free(oi->name);
		return (err);
	}
-
	strlcpy(oi->abi, oi->altabi, sizeof(oi->abi));

-
    for(char *p = oi->altabi; *p; ++p) {
-
        *p = tolower(*p);
-
    }
+
	pkg_arch_to_legacy(oi->abi, oi->altabi, sizeof(oi->abi));

	if (oi->ostype == OS_DRAGONFLY) {
		size_t dsz;

		dsz = strlen(oi->abi);
-
		if (strncasecmp(oi->abi, "DragonFly", 9) == 0) {
-
			for (int i = 0; i < dsz; i++)
-
				oi->abi[i] = tolower(oi->abi[i]);
-
			return (0);
-
		}
-
	}
-

-
	/* Translate architecture string back to regular OS one */
-
	char *arch_tweak = strchr(oi->abi, ':');
-
	if (arch_tweak == NULL)
+
		for (int i = 0; i < dsz; i++)
+
			oi->abi[i] = tolower(oi->abi[i]);
		return (0);
-
	arch_tweak++;
-
	arch_tweak = strchr(arch_tweak, ':');
-
	if (arch_tweak == NULL)
-
		return (0);
-
	arch_tweak++;
-
	for (struct arch_trans *arch_trans = machine_arch_translation; arch_trans->elftype != NULL;
-
	    arch_trans++) {
-
		if (STREQ(arch_tweak, arch_trans->elftype)) {
-
			strlcpy(arch_tweak, arch_trans->archid,
-
			    sizeof(oi->abi) - (arch_tweak - oi->abi));
-
			oi->arch = xstrdup(arch_tweak);
-
			break;
-
		}
	}

	return (0);
modified libpkg/pkg_abi_macho.c
@@ -90,52 +90,12 @@ cputype_to_freebsd_machine_arch(const cpu_type_subtype_t cpu)
	}
}

-
static const char *
-
cputype_to_elfname(const cpu_type_subtype_t cpu)
-
{
-
	switch (cpu.type) {
-
	case CPU_TYPE_ARM:
-
		if (cpu.type_is64) {
-
			return "aarch64:64";
-
		} else {
-
			switch(cpu.subtype_arm) {
-
			case CPU_SUBTYPE_ARM_V7:
-
			case CPU_SUBTYPE_ARM_V7S:
-
			case CPU_SUBTYPE_ARM_V7K:
-
			case CPU_SUBTYPE_ARM_V7M:
-
			case CPU_SUBTYPE_ARM_V7EM:
-
				return "armv7:32:el:eabi:hardfp";
-
			case CPU_SUBTYPE_ARM_V6:
-
			case CPU_SUBTYPE_ARM_V6M:
-
				return "armv6:32:el:eabi:hardfp";
-
			default:
-
				return "arm:32";
-
			}
-
		}
-
	case CPU_TYPE_POWERPC:
-
		if (cpu.type_is64) {
-
			return "powerpc:64:eb";
-
		} else {
-
			return "powerpc:32:eb";
-
		}
-
	case CPU_TYPE_X86:
-
		if (cpu.type_is64) {
-
			return "x86:64";
-
		} else {
-
			return "x86:32";
-
		}
-
	default:
-
		return "other";
-
	}
-
}
-

-

int
pkg_get_myarch_macho(int fd, struct os_info *oi)
{
	ssize_t x;
-
	char *dest = oi->altabi;
-
	size_t sz = sizeof(oi->altabi);
+
	char *dest = oi->abi;
+
	size_t sz = sizeof(oi->abi);

	macho_file_t *mf = 0;
	build_version_t *bv = 0;
@@ -219,7 +179,7 @@ pkg_get_myarch_macho(int fd, struct os_info *oi)
	if (bv) {
		macho_version_t darwin;
		map_platform_to_darwin(&darwin, bv->platform, bv->minos);
-
		snprintf(dest, sz, "Darwin:%d:%s", darwin.major, cputype_to_elfname(mh.cpu));
+
		snprintf(dest, sz, "Darwin:%d:%s", darwin.major, cputype_to_freebsd_machine_arch(mh.cpu));
		if (oi) {
			oi->name = xstrdup("Darwin");
			oi->osversion = darwin.major * 100000 + darwin.minor * 1000 + darwin.patch;
modified libpkg/pkg_elf.c
@@ -1,28 +1,8 @@
/*-
-
 * Copyright (c) 2011-2012 Baptiste Daroussin <bapt@FreeBSD.org>
+
 * Copyright (c) 2011-2024 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2012-2013 Matthew Seaman <matthew@FreeBSD.org>
-
 * 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
-
 *    in this position and unchanged.
-
 * 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.
-
 *
-
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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(S) 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.
+
 * SPDX-License-Identifier: BSD-2-Clause
 */

#ifdef HAVE_CONFIG_H
@@ -166,7 +146,7 @@ shlib_valid_abi(const char *fpath, GElf_Ehdr *hdr)
	 */
	arch[0] = '\0';
	wordsize[0] = '\0';
-
	p = pkg_object_string(pkg_config_get("ALTABI"));
+
	p = ctx.oi->abi;
	for(semicolon = 0; semicolon < 3 && p != NULL; semicolon ++, p ++) {
		p = strchr(p, ':');
		if (p != NULL) {
@@ -742,7 +722,6 @@ elf_note_analyse(Elf_Data *data, GElf_Ehdr *elfhdr, struct os_info *oi)
	return (true);
}

-

int
pkg_get_myarch_elfparse(int fd, struct os_info *oi)
{
@@ -753,12 +732,10 @@ pkg_get_myarch_elfparse(int fd, struct os_info *oi)
	Elf_Scn *scn = NULL;
	int ret = EPKG_OK;
	const char *arch,*abi, *endian_corres_str, *wordsize_corres_str, *fpu;
-
	char *dest = oi->altabi;
-
	size_t sz = sizeof(oi->altabi);
+
	char *dest = oi->abi;
+
	size_t sz = sizeof(oi->abi);
	size_t dsz;

-
	arch = NULL;
-

	if (elf_version(EV_CURRENT) == EV_NONE) {
		pkg_emit_error("ELF library initialization failed: %s",
		    elf_errmsg(-1));
@@ -805,154 +782,15 @@ pkg_get_myarch_elfparse(int fd, struct os_info *oi)
	wordsize_corres_str = elf_corres_to_string(wordsize_corres,
	    (int)elfhdr.e_ident[EI_CLASS]);

-
	arch = elf_corres_to_string(mach_corres, (int) elfhdr.e_machine);
-

-
	switch (elfhdr.e_machine) {
-
	case EM_ARM:
-
		endian_corres_str = elf_corres_to_string(endian_corres,
-
		    (int)elfhdr.e_ident[EI_DATA]);
-

-
		if (elfhdr.e_flags & EF_ARM_VFP_FLOAT)
-
			fpu = "hardfp";
-
		else
-
			fpu = "softfp";
-

-
		if ((elfhdr.e_flags & 0xFF000000) != 0) {
-
			const char *sh_name = NULL;
-
			size_t shstrndx;
-

-
			/* This is an EABI file, the conformance level is set */
-
			abi = "eabi";
-

-
			/* Find which TARGET_ARCH we are building for. */
-
			elf_getshdrstrndx(elf, &shstrndx);
-
			while ((scn = elf_nextscn(elf, scn)) != NULL) {
-
				sh_name = NULL;
-
				if (gelf_getshdr(scn, &shdr) != &shdr) {
-
					scn = NULL;
-
					break;
-
				}
-

-
				sh_name = elf_strptr(elf, shstrndx,
-
				    shdr.sh_name);
-
				if (sh_name == NULL)
-
					continue;
-
				if (STREQ(".ARM.attributes", sh_name))
-
					break;
-
			}
-
			if (scn != NULL && sh_name != NULL) {
-
				data = elf_getdata(scn, NULL);
-
				/*
-
				 * Prior to FreeBSD 10.0 libelf would return
-
				 * NULL from elf_getdata on the .ARM.attributes
-
				 * section. As this was the first release to
-
				 * get armv6 support assume a NULL value means
-
				 * arm.
-
				 *
-
				 * This assumption can be removed when 9.x
-
				 * is unsupported.
-
				 */
-
				if (data != NULL) {
-
					arch = aeabi_parse_arm_attributes(
-
					    data->d_buf, data->d_size);
-
					if (arch == NULL) {
-
						ret = EPKG_FATAL;
-
						pkg_emit_error(
-
						    "unknown ARM ARCH");
-
						goto cleanup;
-
					}
-
				}
-
			} else {
-
				ret = EPKG_FATAL;
-
				pkg_emit_error("Unable to find the "
-
				    ".ARM.attributes section");
-
				goto cleanup;
-
			}
-

-
		} else if (elfhdr.e_ident[EI_OSABI] != ELFOSABI_NONE) {
-
			/*
-
			 * EABI executables all have this field set to
-
			 * ELFOSABI_NONE, therefore it must be an oabi file.
-
			 */
-
			abi = "oabi";
-
                } else {
-
			/*
-
			 * We may have failed to positively detect the ABI,
-
			 * set the ABI to unknown. If we end up here one of
-
			 * the above cases should be fixed for the binary.
-
			 */
-
			ret = EPKG_FATAL;
-
			pkg_emit_error("unknown ARM ABI");
-
			goto cleanup;
-
		}
-
		dsz = strlen(dest);
-
		snprintf(dest + dsz, sz - dsz,
-
		    ":%s:%s:%s:%s:%s", arch, wordsize_corres_str,
-
		    endian_corres_str, abi, fpu);
-
		break;
-
	case EM_MIPS:
-
		/*
-
		 * this is taken from binutils sources:
-
		 * include/elf/mips.h
-
		 * mapping is figured out from binutils:
-
		 * gas/config/tc-mips.c
-
		 */
-
		switch (elfhdr.e_flags & EF_MIPS_ABI) {
-
			case E_MIPS_ABI_O32:
-
				abi = "o32";
-
				break;
-
			case E_MIPS_ABI_N32:
-
				abi = "n32";
-
				break;
-
			default:
-
				if (elfhdr.e_ident[EI_DATA] == ELFCLASS32)
-
					abi = "o32";
-
				else if (elfhdr.e_ident[EI_DATA] == ELFCLASS64)
-
					abi = "n64";
-
				else
-
					abi = "unknown";
-
				break;
-
		}
-
		endian_corres_str = elf_corres_to_string(endian_corres,
-
		    (int)elfhdr.e_ident[EI_DATA]);
+
	if (oi->ostype == OS_FREEBSD && elfhdr.e_machine == EM_X86_64)
+
		oi->arch = xstrdup("amd64");
+
	else if (oi->ostype == OS_DRAGONFLY && elfhdr.e_machine == EM_X86_64)
+
		oi->arch = xstrdup("x86:64");
+
	else
+
		oi->arch = xstrdup(elf_corres_to_string(mach_corres, (int) elfhdr.e_machine));

-
		dsz = strlen(dest);
-
		snprintf(dest + dsz, sz - dsz, ":%s:%s:%s:%s",
-
		    arch, wordsize_corres_str, endian_corres_str, abi);
-
		break;
-
#if defined(EM_RISCV) && defined(EF_RISCV_FLOAT_ABI_MASK)
-
	case EM_RISCV:
-
		switch (elfhdr.e_flags & EF_RISCV_FLOAT_ABI_MASK) {
-
			case EF_RISCV_FLOAT_ABI_SOFT:
-
				abi = "sf";
-
				break;
-
			case EF_RISCV_FLOAT_ABI_DOUBLE:
-
				abi = "hf";
-
				break;
-
			default:
-
				abi = "unknown";
-
				break;
-
		}
-
		dsz = strlen(dest);
-
		snprintf(dest + dsz, sz - dsz, ":%s:%s:%s",
-
		    arch, wordsize_corres_str, abi);
-
		break;
-
#endif
-
	case EM_PPC:
-
	case EM_PPC64:
-
		endian_corres_str = elf_corres_to_string(endian_corres,
-
		    (int)elfhdr.e_ident[EI_DATA]);
-

-
		dsz = strlen(dest);
-
		snprintf(dest + dsz, sz - dsz, ":%s:%s:%s",
-
		    arch, wordsize_corres_str, endian_corres_str);
-
		break;
-
	default:
-
		dsz = strlen(dest);
-
		snprintf(dest + dsz, sz - dsz, ":%s:%s",
-
		    arch, wordsize_corres_str);
-
		break;
-
	}
+
	dsz = strlen(dest);
+
	snprintf(dest + dsz, sz - dsz, ":%s", oi->arch);

cleanup:
	if (elf != NULL)
modified libpkg/private/elf_tables.h
@@ -1,7 +1,7 @@
/*-
 * Copyright (c) 2012 Olivier Houchard <cognet@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -11,7 +11,7 @@
 * 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.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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.
@@ -31,8 +31,8 @@ struct _elf_corres {
};

static const struct _elf_corres mach_corres[] = {
-
	{ EM_386, "x86" },
-
	{ EM_X86_64, "x86" },
+
	{ EM_386, "i386" },
+
	{ EM_X86_64, "x86_64" },
	{ EM_AARCH64, "aarch64" },
	{ EM_ARM, "arm" },
	{ EM_MIPS, "mips" },
modified tests/frontend/abi.sh
@@ -65,12 +65,12 @@ elfparse_body() {
		-o inline:"${_expected}" \
		pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/dfly.bin config altabi

-
	_expected="Linux:3.2:amd64\n"
+
	_expected="Linux:3.2:x86_64\n"
	atf_check \
		-o inline:"${_expected}" \
		pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/linux.bin config abi

-
	_expected="linux:3.2:x86:64\n"
+
	_expected="linux:3.2:x86_64\n"
	atf_check \
		-o inline:"${_expected}" \
		pkg -o IGNORE_OSMAJOR=1 -o ABI_FILE=$(atf_get_srcdir)/linux.bin config altabi