Project:Toolchain/Binutils 2.34 porting notes/undefined reference to bfd get section *

From Gentoo Wiki
Jump to:navigation Jump to:search

The problem

Starting from binutils-2.34 macros to access section attributes changed slightly: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=fd3619828e94a24a92cddec42cbc0ab33352eeb4

Code like the following will fail to build:

CODE
uintptr_t vma = (uintptr_t)bfd_get_section_vma(bfdh, section);
uintptr_t sz = (uintptr_t)bfd_get_section_size(section);


 linux/bfd.c:125:36: warning: implicit declaration of function 'bfd_get_section_vma'; did you mean 'bfd_set_section_vma'? [-Wimplicit-function-declaration]
 125 |         uintptr_t vma = (uintptr_t)bfd_get_section_vma(bfdh, section);
     |                                    bfd_set_section_vma
 ld: bfd.c:(.text+0x4ff): undefined reference to `bfd_get_section_vma'

The fix

The fix is simple: just drop _get_ and bfdh parameters:

CODE
uintptr_t vma = (uintptr_t)bfd_section_vma(section);
uintptr_t sz = (uintptr_t)bfd_section_size(section);

Links and examples

- Upstream commit: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=fd3619828e94a24a92cddec42cbc0ab33352eeb4 - Example fix: bug #707846