Date: Fri, 27 Sep 2019 19:07:11 +0000 (UTC) From: Ed Maste <emaste@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r352809 - head/tools/tools/controlelf Message-ID: <201909271907.x8RJ7B8S041004@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: emaste Date: Fri Sep 27 19:07:11 2019 New Revision: 352809 URL: https://svnweb.freebsd.org/changeset/base/352809 Log: controlelf: exit with error if file endianness does not match host We need to add support for cross-endian operation, but until that's done just exit with an error rather than misbehaving. Modified: head/tools/tools/controlelf/controlelf.c Modified: head/tools/tools/controlelf/controlelf.c ============================================================================== --- head/tools/tools/controlelf/controlelf.c Fri Sep 27 18:49:13 2019 (r352808) +++ head/tools/tools/controlelf/controlelf.c Fri Sep 27 19:07:11 2019 (r352809) @@ -30,6 +30,7 @@ #include <sys/param.h> #include <sys/elf_common.h> +#include <sys/endian.h> #include <sys/stat.h> #include <err.h> @@ -70,6 +71,12 @@ static struct option long_opts[] = { { NULL, 0, NULL, 0 } }; +#if BYTE_ORDER == LITTLE_ENDIAN +#define SUPPORTED_ENDIAN ELFDATA2LSB +#else +#define SUPPORTED_ENDIAN ELFDATA2MSB +#endif + int main(int argc, char **argv) { @@ -140,6 +147,15 @@ main(int argc, char **argv) if (gelf_getehdr(elf, &ehdr) == NULL) { warnx("gelf_getehdr: %s", elf_errmsg(-1)); + retval = 1; + goto fail; + } + /* + * XXX need to support cross-endian operation, but for now + * exit on error rather than misbehaving. + */ + if (ehdr.e_ident[EI_DATA] != SUPPORTED_ENDIAN) { + warnx("file endianness must match host"); retval = 1; goto fail; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201909271907.x8RJ7B8S041004>