Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Use MACHINE_ARCH to define abi
Baptiste Daroussin committed 11 years ago
commit 9946e92027405f90a356ef29d8fbf4a31f277b33
parent 295f01f
5 files changed +92 -9
modified libpkg/pkg.h.in
@@ -1612,6 +1612,7 @@ int pkg_recompute(struct pkgdb *, struct pkg *);
int pkgdb_reanalyse_shlibs(struct pkgdb *, struct pkg *);

int pkg_get_myarch(char *pkgarch, size_t sz);
+
int pkg_get_myarch_legacy(char *pkgarch, size_t sz);

void pkgdb_cmd(int argc, char **argv);
int pkg_old_load_from_path(struct pkg *pkg, const char *path);
modified libpkg/pkg_config.c
@@ -71,7 +71,7 @@ struct config_entry {
	const char *desc;
};

-
static char myabi[BUFSIZ];
+
static char myabi[BUFSIZ], myabi_legacy[BUFSIZ];
static struct pkg_repo *repos = NULL;
ucl_object_t *config = NULL;

@@ -143,6 +143,12 @@ static struct config_entry c[] = {
		"Override the automatically detected ABI",
	},
	{
+
		PKG_STRING,
+
		"ALTABI",
+
		myabi_legacy,
+
		"Override the automatically detected old-form ABI",
+
	},
+
	{
		PKG_BOOL,
		"DEVELOPER_MODE",
		"NO",
@@ -712,6 +718,7 @@ pkg_ini(const char *path, const char *reposdir, pkg_init_flags flags)
	o = NULL;

	pkg_get_myarch(myabi, BUFSIZ);
+
	pkg_get_myarch_legacy(myabi_legacy, BUFSIZ);
	if (parsed != false) {
		pkg_emit_error("pkg_init() must only be called once");
		return (EPKG_FATAL);
modified libpkg/pkg_elf.c
@@ -673,8 +673,8 @@ aeabi_parse_arm_attributes(void *data, size_t length)
#undef MOVE
}

-
int
-
pkg_get_myarch(char *dest, size_t sz)
+
static int
+
pkg_get_myarch_elfparse(char *dest, size_t sz)
{
	Elf *elf = NULL;
	GElf_Ehdr elfhdr;
@@ -687,7 +687,6 @@ pkg_get_myarch(char *dest, size_t sz)
	char *osname;
	uint32_t version = 0;
	int ret = EPKG_OK;
-
	int i;
	const char *arch, *abi, *endian_corres_str, *wordsize_corres_str, *fpu;
	const char *path;

@@ -757,9 +756,6 @@ pkg_get_myarch(char *dest, size_t sz)
	else
		version = le32dec(src);

-
	for (i = 0; osname[i] != '\0'; i++)
-
		osname[i] = (char)tolower(osname[i]);
-

	wordsize_corres_str = elf_corres_to_string(wordsize_corres,
	    (int)elfhdr.e_ident[EI_CLASS]);

@@ -894,6 +890,53 @@ cleanup:
}

int
+
pkg_get_myarch_legacy(char *dest, size_t sz)
+
{
+
	int i, err;
+

+
	err = pkg_get_myarch_elfparse(dest, sz);
+
	if (err)
+
		return (err);
+

+
	for (i = 0; i < strlen(dest); i++)
+
		dest[i] = tolower(dest[i]);
+

+
	return (0);
+
}
+

+
int
+
pkg_get_myarch(char *dest, size_t sz)
+
{
+
	struct arch_trans *arch_trans;
+
	char *arch_tweak;
+

+
	int err;
+
	err = pkg_get_myarch_elfparse(dest, sz);
+
	if (err)
+
		return (err);
+

+
	/* Translate architecture string back to regular OS one */
+
	arch_tweak = strchr(dest, ':');
+
	if (arch_tweak == NULL)
+
		return (0);
+
	arch_tweak++;
+
	arch_tweak = strchr(arch_tweak, ':');
+
	if (arch_tweak == NULL)
+
		return (0);
+
	arch_tweak++;
+
	for (arch_trans = machine_arch_translation; arch_trans->elftype != NULL;
+
	    arch_trans++) {
+
		if (strcmp(arch_tweak, arch_trans->elftype) == 0) {
+
			strlcpy(arch_tweak, arch_trans->archid,
+
			    sz - (arch_tweak - dest));
+
			break;
+
		}
+
	}
+

+
	return (0);
+
}
+

+
int
pkg_suggest_arch(struct pkg *pkg, const char *arch, bool isdefault)
{
	bool iswildcard;
modified libpkg/private/elf_tables.h
@@ -68,4 +68,34 @@ static const struct _elf_corres os_corres[] = {
#define NT_VERSION	1
#define NT_ARCH	2

+
/* All possibilities on FreeBSD as of 5/26/2014 */
+
struct arch_trans {
+
	const char *elftype;
+
	const char *archid;
+
};
+

+
static struct arch_trans machine_arch_translation[] = {
+
	{ "x86:32", "i386" },
+
	{ "x86:64", "amd64" },
+
	{ "powerpc:32", "powerpc" },
+
	{ "powerpc:64", "powerpc64" },
+
	{ "sparc64:64", "sparc64" },
+
	{ "ia64:64", "ia64" },
+
	/* All the ARM stuff */
+
	{ "arm:32:el:eabi:softfp", "arm" },
+
	{ "arm:32:el:oabi:softfp", "arm" },
+
	{ "arm:32:eb:eabi:softfp", "armeb" },
+
	{ "arm:32:eb:oabi:softfp", "armeb" },
+
	{ "armv6:32:el:eabi:softfp", "armv6" },
+
	/* And now MIPS */
+
	{ "mips:32:el:o32", "mipsel" },
+
	{ "mips:32:el:n32", "mipsn32el" },
+
	{ "mips:32:eb:o32", "mips" },
+
	{ "mips:32:eb:n32", "mipsn32" },
+
	{ "mips:64:el:n64", "mips64el" },
+
	{ "mips:64:eb:n64", "mips64" },
+

+
	{ NULL, NULL }
+
};
+

#endif /* ELF_TABLES_H_ */
modified libpkg/utils.c
@@ -566,12 +566,14 @@ check_for_hardlink(struct hardlinks **hl, struct stat *st)

bool
is_valid_abi(const char *arch, bool emit_error) {
-
	const char *myarch;
+
	const char *myarch, *myarch_legacy;

	myarch = pkg_object_string(pkg_config_get("ABI"));
+
	myarch_legacy = pkg_object_string(pkg_config_get("ALTABI"));

	if (fnmatch(arch, myarch, FNM_CASEFOLD) == FNM_NOMATCH &&
-
	    strncmp(arch, myarch, strlen(myarch)) != 0) {
+
	    strncasecmp(arch, myarch, strlen(myarch)) != 0 &&
+
	    strncasecmp(arch, myarch_legacy, strlen(myarch_legacy)) != 0) {
		if (emit_error)
			pkg_emit_error("wrong architecture: %s instead of %s",
			    arch, myarch);