strange OS dependent behavior of bfd_get_flavour()
Peng Yu
pengyu.ut@gmail.com
Fri Apr 30 05:15:41 GMT 2021
Hi,
#define PACKAGE 1
#define PACKAGE_VERSION 1
#include <bfd.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
bfd_init();
bfd *bfd_h = bfd_openr(argv[1], 0);
printf("bfd_get_flavour(bfd_h) = %d\n", bfd_get_flavour(bfd_h));
bfd_close(bfd_h);
}
For the above C file, it returns the following on macOS.
$ ./main.exe test_file
bfd_get_flavour(bfd_h) = 17
But it returns the following macOS.
$ ./main.exe test_file
bfd_get_flavour(bfd_h) = 5
test_file is always the following
$ file test_file
test_file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV),
statically linked, not stripped
The number 5 is bfd_target_elf_flavour.
The number 17 is bfd_target_mach_o_flavour.
This result seems to indicate bfd_get_flavour() returns the OS on
which it runs. I don't find the doc of bfd_get_flavour(). But
shouldn't it return the info about the input file to bfd_openr()?
https://sourceware.org/binutils/docs/bfd/index.html
This result is confusing to me. Could anybody clarify what is going on
here? Thanks.
--
Regards,
Peng
More information about the Binutils
mailing list