*BSD News Article 90610


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.rmit.EDU.AU!goanna.cs.rmit.edu.au!news.apana.org.au!cantor.edge.net.au!news.teragen.com.au!news.access.net.au!news.mel.connect.com.au!news.mel.aone.net.au!grumpy.fl.net.au!news.webspan.net!newsfeeds.sol.net!news.maxwell.syr.edu!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!rill.news.pipex.net!pipex!dispatch.news.demon.net!demon!fido.news.demon.net!demon!sun4nl!wins.uva.nl!not-for-mail
From: frank@wins.uva.nl (Frank van der Linden)
Newsgroups: comp.unix.bsd.netbsd.misc
Subject: Re: i386 netbsd 1.1, ELF, and Linux
Date: 8 Mar 1997 14:30:53 +0100
Organization: FWINS, University of Amsterdam
Distribution: world
Message-ID: <5frpmd$2ql@mail.wins.uva.nl>
References: <331FDC81.159D@us.oracle.com> <5fp18e$69v@mail.wins.uva.nl> <5fqr22$9f@vixen.cso.uiuc.edu>
NNTP-Posting-Host: mail.wins.uva.nl
Lines: 110
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.netbsd.misc:5580

haszlaki@students.uiuc.edu (eric richard haszlakiewicz) writes:

>	hmm.. in a similar excersize, I'm running 1.2-current and
>trying to run xquake.  I have COMPAT_LINUX, EXEC_ELF32 on, and SVR4 off.
>Same problem.  Anyone know how to get it to work?  Or if not, why it
>doesn't work?

I've heard about several people who did get it to run (and so did I,
but I threw away all the binaries again). You may be missing
the right dynamic linker, or have it in the wrong place (ld-linux.so.1).

You could try to run the following program, and check if you have
the interpreter it finds in the binary installed.

If you're getting 'bad system call' messages, try compiling a kernel
with KTRACE, use ktrace/kdump, and send me the output of that.

- Frank


#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, *note;
  Elf32_Ehdr hdr;
  Elf32_Phdr ph;
  off_t pos;
  int namesz, descsz, type;

  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 == Elf_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 == Elf_pt_load) {
      printf("loadable section:      %x (prot %x)\n", ph.p_vaddr, ph.p_flags);
      continue;
    }

    if (ph.p_type == Elf_pt_phdr) {
      printf("program header:        %x \n", ph.p_vaddr);
      continue;
    }

    if (ph.p_type == Elf_pt_note) {
      pos = lseek(fd, 0, SEEK_CUR);
      if (lseek(fd, ph.p_offset, SEEK_SET) < 0) {
        perror("lseek");
        exit(1);
      }
      read(fd, &namesz, 4);
      read(fd, &descsz, 4);
      read(fd, &type, 4);
      note = (char *)malloc(ph.p_filesz);
      read(fd, note, ph.p_filesz);
      lseek(fd, pos, SEEK_SET);
      printf("note section found, length %d type %d: \"%s\"\n", namesz - 1,
        type, note);
    }
  }
  return 0;
}