[linux-elitists] BFD and libiberty

Jason Spence jspence@lightconsulting.com
Mon Nov 10 08:44:41 PST 2003

On Sun, Nov 09, 2003 at 10:55:12PM -0800, Greg KH wrote: 
> On Sun, Nov 09, 2003 at 07:13:59PM -0800, Jason Spence wrote:
> > 
> > Something else that's kind of bugging me is that libbfd requires you
> > to call bfd_check_format() on the target object and play guessing
> > games for each possible type before it'll fill out the rest of the bfd
> > structure so the other API calls don't crash when you pass them the
> > bfd.  As far as I can tell, that's the only way to get the rest of the
> > bfd filled out.  Is it just me, or is this actually as clunky as I
> > think it is?
> It's not just you, I ran into the same problem last time I did any BFD
> coding.  I just hard-coded the target to i686-pc-linux-gnu with a call
> to bfd_set_default_target("i686-pc-linux-gnu") which solved my problems.
> But I knew I was only playing around with elf format files, you might
> not be able to get away with this.

Actually, calling bfd_set_default_target() doesn't fill out the bfd
completely like bfd_check_format() does, at least using the bfd from

My dinky test programs don't have to call bfd_set_default_target on
either Linux or Win32 in order to get correct operation, but I still
have to play guessing games with BFD ("I'm not teeeeelllllling!!!")
via bfd_check_format() in order to make things work.

> There is the libelf library if you want another choice in dealing with
> object files.  But I found that libbfd was easier to use in the end,
> which really amazed me.

Har, you should see what the vendor provides on VMS and OS/390.
Actually, Windows provides a fairly complete library called dbghelp
which combines the good parts of libiberty, bfd, and chunks of the gdb
source.  Unfortunately it's like 2-3 ksloc to dump a minidump that
covers all the stuff a support tech might need, but at least I get
abstraction primitives to do something like that with.  Getting
reliable core dumps of multithreaded applications on Linux is, um, a
lot more than 2-3 ksloc.

One funny thing I noticed about all these operating systems is that if
a segv handler (or equivilent) crashes, you enter an infinite crash
loop.  The number of crashes per second can be used as a primitive
benchmark of the system's context switching performance, since the
processor chucks an async exception at the task for each segv...

 - Jason       Last known location:  11.0 miles northeast of MOUNTAIN VIEW, CA

Eggheads unite!  You have nothing to lose but your yolks.
		-- Adlai Stevenson

More information about the linux-elitists mailing list