From 9439877e985eb4df023ef814794a47111ca4d892 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 26 Sep 2013 07:53:18 +0000 Subject: [PATCH] Add an elf note on ARM to store the MACHINE_ARCH an executable was built for. This is useful for software needing to know which architecture a binary is built for as arm and armv6 have slight differences meaning only some binaries build for one will work as expected on the other. It is expected pkgng will be able to make use of this to simplify the logic to determine which package ABI to use. Approved by: re (kib) --- contrib/binutils/binutils/readelf.c | 2 ++ contrib/binutils/include/elf/common.h | 1 + lib/csu/arm/crt1.c | 14 ++++++++++++++ lib/csu/common/notes.h | 1 + 4 files changed, 18 insertions(+) diff --git a/contrib/binutils/binutils/readelf.c b/contrib/binutils/binutils/readelf.c index a4adb780f306..d2e2aefca383 100644 --- a/contrib/binutils/binutils/readelf.c +++ b/contrib/binutils/binutils/readelf.c @@ -9169,6 +9169,8 @@ get_freebsd_note_type (unsigned e_type) return _("NT_FREEBSD_ABI_TAG"); case NT_FREEBSD_NOINIT_TAG: return _("NT_FREEBSD_NOINIT_TAG"); + case NT_FREEBSD_ARCH_TAG: + return _("NT_FREEBSD_ARCH_TAG"); default: break; } diff --git a/contrib/binutils/include/elf/common.h b/contrib/binutils/include/elf/common.h index 17ca0d56c605..d4d9d7b0cc7a 100644 --- a/contrib/binutils/include/elf/common.h +++ b/contrib/binutils/include/elf/common.h @@ -456,6 +456,7 @@ #define NT_FREEBSD_TAG 1 #define NT_FREEBSD_NOINIT_TAG 2 +#define NT_FREEBSD_ARCH_TAG 3 /* These three macros disassemble and assemble a symbol table st_info field, which contains the symbol binding and symbol type. The STB_ and STT_ diff --git a/lib/csu/arm/crt1.c b/lib/csu/arm/crt1.c index e3529b81dd05..d9f8a2d07a5b 100644 --- a/lib/csu/arm/crt1.c +++ b/lib/csu/arm/crt1.c @@ -115,6 +115,20 @@ __start(int argc, char **argv, char **env, struct ps_strings *ps_strings, exit(main(argc, argv, env)); } +static const struct { + int32_t namesz; + int32_t descsz; + int32_t type; + char name[sizeof(NOTE_FREEBSD_VENDOR)]; + char desc[sizeof(MACHINE_ARCH)]; +} archtag __attribute__ ((section (NOTE_SECTION), aligned(4))) __used = { + .namesz = sizeof(NOTE_FREEBSD_VENDOR), + .descsz = sizeof(int32_t), + .type = ARCH_NOTETYPE, + .name = NOTE_FREEBSD_VENDOR, + .desc = MACHINE_ARCH +}; + #ifdef GCRT __asm__(".text"); __asm__("eprol:"); diff --git a/lib/csu/common/notes.h b/lib/csu/common/notes.h index fcc2b6684617..b2c53bf0351c 100644 --- a/lib/csu/common/notes.h +++ b/lib/csu/common/notes.h @@ -34,5 +34,6 @@ #define ABI_NOTETYPE 1 #define CRT_NOINIT_NOTETYPE 2 +#define ARCH_NOTETYPE 3 #endif