Subject: Re: An annoying failure I've seen a lot of.
To: Dave Burgess <burgess@cynjut.neonramp.com>
From: Frank van der Linden <frank@fwi.uva.nl>
List: current-users
Date: 08/27/1996 10:11:35
Quoting Dave Burgess,
> Whenever I try to run an ELF or COFF binary, I get the following error:
> ./linux.x86: 1: Syntax error: "(" unexpected
> This one happens to be from the 'StarOffice' installation. A 'file' in
> linux.x86 confirms the following:
> inst-files/linux.x86: ELF 32-bit LSB executable, Intel 80386, version 1
If it's a dynamically linked binary, what you could be seeing is
a missing dynamic linker. Try to run the following program as
<whatever> linux.x86 and tell me what it says.
----
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/exec_elf.h>
int main(int argc, char **argv)
{
int fd, i;
char *interp;
Elf32_Ehdr hdr;
Elf32_Phdr ph;
off_t pos;
if (argc != 2) {
fprintf(stderr, "Usage: elfdump <file>\n");
exit(1);
}
if ((fd = open(argv[1], O_RDONLY)) < 0) {
perror(argv[1]);
exit(1);
}
if (read(fd, &hdr, sizeof hdr) < sizeof hdr ||
strncmp(hdr.e_ident, Elf32_e_ident, Elf32_e_siz)) {
fprintf(stderr, "%s: not an ELF binary.\n");
exit(1);
}
printf("file type: %d\n", hdr.e_type);
printf("machine type: %d\n", hdr.e_machine);
printf("version: %d\n", hdr.e_version);
printf("program header offset: %x\n", hdr.e_phoff);
printf("section header offset: %x\n", hdr.e_shoff);
printf("processor flags: %x\n", hdr.e_flags);
printf("entry: %x\n", hdr.e_entry);
if (lseek(fd, hdr.e_phoff, SEEK_SET) < 0) {
perror("lseek");
exit(1);
}
for (i = 0; i < hdr.e_phnum; i++) {
if (read(fd, &ph, sizeof ph) < sizeof ph) {
fprintf(stderr, "I/O error examining ELF sections.\n");
exit(1);
}
if (ph.p_type == Elf32_pt_interp) {
pos = lseek(fd, 0, SEEK_CUR);
interp = (char *) malloc(ph.p_filesz);
if (lseek(fd, ph.p_offset, SEEK_SET) < 0) {
perror("lseek");
exit(1);
}
read(fd, interp, ph.p_filesz);
lseek(fd, pos, SEEK_SET);
printf("interpreter: %s\n", interp);
continue;
}
if (ph.p_type == Elf32_pt_load) {
printf("loadable section: %x (prot %x)\n", ph.p_vaddr, ph.p_flags);
continue;
}
if (ph.p_type == Elf32_pt_phdr) {
printf("program header: %x \n", ph.p_vaddr);
continue;
}
if (ph.p_type == Elf32_pt_note)
printf("note section found.\n");
}
return 0;
}
------