Binary file formats glibc pdp--- Help please

Binary file formats glibc pdp--- Help please

Post by Michael Toa » Tue, 04 Sep 2001 01:29:53



Here is a section of my code.

I am writing 0x12345678 to a binary file.
Rewind to the begining of the file and then read the value I have just
written.

Running this section of code gives

WriteData: 12345678
ReadData: 8048581

When I use beav to look at the file I get:

78 56 34 12

Any help is greatly appreciated.

Red Hat Linux 7.1
Digital Venturis 5133
gcc 2.96

Michael Toal

bin = fopen(filename, "wb") ;
      if( !bin )
      {
         fprintf(stderr, "<IMAGE::read> : %s cannot be read\n",
            filename) ;
         return (-1) ;
      }

      WriteData = 0x12345678;

      fprintf(stderr, "No file error: %s \n",filename) ;

      fwrite(&WriteData, sizeof(int), 1, bin);
      rewind(bin);
      fread(&ReadData, sizeof(int), 1, bin);

      fprintf(stderr, " WriteData: %x\n",WriteData);
      fprintf(stderr, " ReadData: %x\n",ReadData);

 
 
 

Binary file formats glibc pdp--- Help please

Post by Karl Heye » Tue, 04 Sep 2001 03:24:05




> Here is a section of my code.

> I am writing 0x12345678 to a binary file. Rewind to the begining of the file
> and then read the value I have just written.

> Running this section of code gives

> WriteData: 12345678
> ReadData: 8048581

> When I use beav to look at the file I get:

> 78 56 34 12

x86 has always stored things as little endian.  look at the htonl type
functions.

Quote:> bin = fopen(filename, "wb") ;

open the file for writing!!!!!!!!

Quote:>       if( !bin )
>       {
>          fprintf(stderr, "<IMAGE::read> : %s cannot be read\n",
>             filename) ;
>          return (-1) ;
>       }

>       WriteData = 0x12345678;

>       fprintf(stderr, "No file error: %s \n",filename) ;

>       fwrite(&WriteData, sizeof(int), 1, bin); rewind(bin);
>       fread(&ReadData, sizeof(int), 1, bin);

No check for error, trying to read from a write only file!!!

Quote:>       fprintf(stderr, " WriteData: %x\n",WriteData); fprintf(stderr, "
>       ReadData: %x\n",ReadData);

ReadData does not have any useful data.

karl.

 
 
 

1. Can primary glibc 2.1.x coexist with non-primary glibc 2.2.x WRT shared binaries?

I'd like to install and use a non-primary glibc 2.2.x on a system with glibc
2.1.x as the primary glibc (2.2.x and 2.1.x are incompatible).  All system
binaries are shared and expect glibc 2.1.x.  My goal is to build and run
shared binaries using the non-primary glibc 2.2.x on the same system as
well.
All the FAQs and HOWTOs that I've seen about using non-primary glibc2
assume that the primary glibc is glibc1.  This is pretty easy, since glibc1
used ld-linux.so.1, and glibc2 uses ld-linux.so.2, so there's no
collision between the dynamic linker/loaders.   But glibc 2.1.x and
glibc 2.2.x BOTH use "ld-linux.so.2".  I've worked around this by changing
the
link in mynon-primary glibc2.2.1 (installed in /usr/local/testglibc2.2.1)
from
"ld-linux.so.2" to "ld-linux.so.3", and binary-patched the 2.2.x libc.so.6
to refer to the ld-linux.so.3 (if I don't do this, the system uses
/lib/ld-linux.so.2, which points to ld-2.1.3.so, and the glibc 2.2.x
shared binary doesn't load).

My makefile for a simple hello world shared binary (using the non-primary
glibc 2.2.x) is as follows:

testglibc = /usr/local/testglibc2.2.1
gcc = gcc
.PHONY: all
all: hello
hello: hello.o
 $(gcc) -v -shared -fPIC -Wl,-t \
  -Wl,--dynamic-linker=$(testglibc)/lib/ld-2.2.1.so \
  -B$(testglibc)/lib/ \
  -Wl,-rpath=$(testglibc)/lib \

hello.o: hello.c

clean:
 rm -f  hello hello.o

The resulting binary compiles and links, and ldd shows all the right
libraries being referenced (all in /usr/local/testglibc2.2.1/lib),
but when run it seg faults.

Several people I've talked to about this say "yeah, I've done that"
but haven't offered any concrete instructions or makefiles, etc., on
how to do this.   Again, the glibc FAQ that I can see does NOT address
this scenario.  Any light that anyone can shed on the matter would be
most appreciated.

2. Locked out after SLS installation; Default root passwd?

3. Anyone (else) make PDP++ Binaries?

4. WABI 2.1 Won't load MSOffice 4.2, 4.3

5. (error : cannot execute binary file ) problem, please help !

6. Reading is much more interesting than TV (0676/1708)

7. Please Help RH6.0 DOSEMU cannot execute binary files

8. FS: Persoft Smarterm Office Version 8.0 for Win9X / NT

9. help: how to build glibc for a.out format on linux

10. gdb: core file not in executable format: File format not recognized

11. Convert vc file format to Lotus 1-2-3 file format?

12. Moving from libc5 to glibc 2.0.4 binaries (Help or HowTo?)

13. THIS FILE IS IN BINARY FORMAT...