[RESOLVED] Binutils .a issue

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Haoud
Member
Member
Posts: 31
Joined: Wed Aug 10, 2016 3:07 am
Libera.chat IRC: Haoud

[RESOLVED] Binutils .a issue

Post by Haoud »

Hello,
I am currently trying to port gcc and binutils to my operating system. I am currently using Newlib 2.5.0, GCC 5.2.0 and binutils 2.25.
I have cross compiled binutils and gcc for my OS and their work and it seems to be functioning correctly.
I'm trying to compile a very simple program under my OS:

Code: Select all

int main(int argc, char *argv[])
{
    return 0;
}
I use this command to compile:

Code: Select all

gcc -fno-use-linker-plugin /test.c
GCC correctly generates the. o file but binutils can't link it to the. a libraries (libgcc. a, libc. a, libnosys.a ...)
I get this error for all .a file:

Code: Select all

libgcc.a: file not recognized: file format not recognized
But my libraries work perfectly because if I compile with

Code: Select all

gcc -c /test.c
and that I link with the same libraries with my cross ld but under linux, it works and i get a valid executable that I can launch under my OS (and that doesn't do anything but is running well)

Anybody have any ideas on how to solve this problem? Thank you

EDIT: Under my OS, ar does'nt recognized .a files too but under linux, i386-haoudos-ar recognized it. It's strange...
Last edited by Haoud on Fri Dec 29, 2017 5:21 am, edited 2 times in total.
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: HOSTED BINUTILS link with libc.a problem

Post by max »

Hey,

with what modifications / configure options did you compile your host binutils?

Greets
Haoud
Member
Member
Posts: 31
Joined: Wed Aug 10, 2016 3:07 am
Libera.chat IRC: Haoud

Re: HOSTED BINUTILS link with libc.a problem

Post by Haoud »

Hello, thank you for your response
I made the same changes as in the tutorial by replacing "myos" with "haoudos" and "i686" with "i386".
I use this shell script to compile binutils:

Code: Select all

export PATH=$HOME/cross/bin:$PATH
export SYSROOT=$HOME/sysroot
export PREFIX=/bin
cd $HOME/src/binutils-2.25/build
../binutils/configure --target=i386-haoudos --host=i386-haoudos --disable-multilib  -with-arch=i386 --prefix="$PREFIX" --with-sysroot-build="$SYSROOT" -with-sysroot=/ --disable-werror --enable-nls --with-pkgversion="Binutils 2.25 for HaoudOS"
make all -j8
make DESTDIR=$SYSROOT install
ans to compile gcc:

Code: Select all

export PATH=$HOME/cross/bin:$PATH
export SYSROOT=$HOME/sysroot
export PREFIX=/bin
cd $HOME/src/gcc-5.2.0/build
make distclean
../gcc-5.2.0/configure --prefix="$PREFIX" --target=i386-haoudos --host=i386-haoudos --with-arch=i386 --disable-shared --disable-multilib --with-newlib --with-sysroot-build="$SYSROOT" --with-sysroot=/ --enable-languages=c,c++  --with-pkgversion="GCC 5.2.0 for HaoudOS"
make all-gcc -j8
make all-target-libgcc -j8
make DESTDIR=$SYSROOT install-gcc 
make DESTDIR=$SYSROOT install-target-libgcc
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: HOSTED BINUTILS link with libc.a problem

Post by iansjack »

Such compiler did you use to produce your .a files? Are you sure it is a 32-bit one?
Haoud
Member
Member
Posts: 31
Joined: Wed Aug 10, 2016 3:07 am
Libera.chat IRC: Haoud

Re: HOSTED BINUTILS link with libc.a problem

Post by Haoud »

I think my .a file are 32-bit but I'm not sure.
I don't get precision with command "file" (libgcc.a: current ar file).
Ho I get more information about libraries?
I noticed several strange things:
- These libraries work very well with the cross compiler for my OS: for example, if I ask GCC (under my OS) to produce .o file, I can correctly link it with the cross compiler for my OS (under linux) and run the executable produced under my OS.
- If i run "strip" on .a file, the error disappears but I get another link error (I'm not home yet, I'll describe the mistake more precisely as soon as I can) on string index and a error like "crt0.o: no .eh_frame_hdr table will be created")
Haoud
Member
Member
Posts: 31
Joined: Wed Aug 10, 2016 3:07 am
Libera.chat IRC: Haoud

Re: HOSTED BINUTILS link with libc.a problem

Post by Haoud »

OK, when I run:

Code: Select all

readelf libgcc.a -h
I get this error:

Code: Select all

readelf: Error: Archive member uses long names, but no longname table found
readelf: Error: libgcc.a: bad archive file name 
EDIT:After a few weeks of debugging, I realized that my lseek system call did not return the position in the file after moving into the file. I've corrected that and everything went back in order.
Post Reply