summaryrefslogtreecommitdiffstats
path: root/usr.bin/ldd
diff options
context:
space:
mode:
authoredwin <edwin@FreeBSD.org>2008-07-21 02:13:14 +0000
committeredwin <edwin@FreeBSD.org>2008-07-21 02:13:14 +0000
commit7b9be5566f6e413275dcc75aa727f8f5ed74ee99 (patch)
tree619de3ba5e9e08b449da8f705cd9eeff80b8742f /usr.bin/ldd
parentfd0203e8815fb7fa34adf77baedda187e8652fcf (diff)
downloadFreeBSD-src-7b9be5566f6e413275dcc75aa727f8f5ed74ee99.zip
FreeBSD-src-7b9be5566f6e413275dcc75aa727f8f5ed74ee99.tar.gz
After the commit of SVN rev 180236, wilko@ noticed that the approach
doesn't work on the Alpha platform: machine/elf.h doesn't include sys/elf32.h there. PR: related to bin/124906 Approved by: bde@ MFC after: 1 week
Diffstat (limited to 'usr.bin/ldd')
-rw-r--r--usr.bin/ldd/ldd.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/usr.bin/ldd/ldd.c b/usr.bin/ldd/ldd.c
index 9a7feba..3e6a072 100644
--- a/usr.bin/ldd/ldd.c
+++ b/usr.bin/ldd/ldd.c
@@ -48,6 +48,18 @@ __FBSDID("$FreeBSD$");
#include "extern.h"
+/*
+ * Elf32_xhdr structures can only be used if sys/elf32.h is included, so
+ * check for the existence of one of the macros defined in sys/elf32.h.
+ *
+ * The presense of the ELF32_R_TYPE macro via machine/elf.h has been verified
+ * on amd64 6.3, ia64 7.0 and sparc64 7.0. The absence of the macro has been
+ * verified on alpha 6.2.
+ */
+#if defined(ELF32_R_TYPE)
+#define ELF32_SUPPORTED
+#endif
+
static int is_executable(const char *fname, int fd, int *is_shlib,
int *type);
static void usage(void);
@@ -55,7 +67,7 @@ static void usage(void);
#define TYPE_UNKNOWN 0
#define TYPE_AOUT 1
#define TYPE_ELF 2 /* Architecture default */
-#if __ELF_WORD_SIZE > 32
+#if __ELF_WORD_SIZE > 32 && defined(ELF32_SUPPORTED)
#define TYPE_ELF32 3 /* Explicit 32 bits on architectures >32 bits */
#endif
@@ -73,7 +85,7 @@ const char *envdef[ENV_LAST] = {
"LD_TRACE_LOADED_OBJECTS_PROGNAME",
"LD_TRACE_LOADED_OBJECTS_ALL",
};
-#if __ELF_WORD_SIZE > 32
+#if __ELF_WORD_SIZE > 32 && defined(ELF32_SUPPORTED)
const char *env32[ENV_LAST] = {
"LD_32_TRACE_LOADED_OBJECTS",
"LD_32_TRACE_LOADED_OBJECTS_FMT1",
@@ -154,7 +166,7 @@ main(int argc, char *argv[])
case TYPE_AOUT:
env = envdef;
break;
-#if __ELF_WORD_SIZE > 32
+#if __ELF_WORD_SIZE > 32 && defined(ELF32_SUPPORTED)
case TYPE_ELF32:
env = env32;
break;
@@ -229,7 +241,9 @@ is_executable(const char *fname, int fd, int *is_shlib, int *type)
{
union {
struct exec aout;
+#if __ELF_WORD_SIZE > 32 && defined(ELF32_SUPPORTED)
Elf32_Ehdr elf32;
+#endif
Elf_Ehdr elf;
} hdr;
int n;
@@ -256,7 +270,7 @@ is_executable(const char *fname, int fd, int *is_shlib, int *type)
return (1);
}
-#if __ELF_WORD_SIZE > 32
+#if __ELF_WORD_SIZE > 32 && defined(ELF32_SUPPORTED)
if ((size_t)n >= sizeof(hdr.elf32) && IS_ELF(hdr.elf32) &&
hdr.elf32.e_ident[EI_CLASS] == ELFCLASS32) {
/* Handle 32 bit ELF objects */
OpenPOWER on IntegriCloud