Questions tagged [binutils]
The GNU binary utilities. A collection of tools for operating on object files. Most notably they include the GNU assembler and linker. They are typically used in conjunction with the GNU compiler collection (GCC).
binutils
424
questions
66
votes
8
answers
82k
views
How to list library dependencies of a non-native binary?
When developing for native platform, I can use ldd to list all the shared libraries (.so files) a binary executable I build will try to load upon start-up. But when cross-compiling, I don't know how ...
63
votes
3
answers
32k
views
How clear gdb command screen?
Is it possible to clear the command window of gdb? I mean, is there a command in gdb that do the same (for the command windows) as the clear command in a bash terminal?
45
votes
5
answers
59k
views
How to extract only the raw contents of an ELF section?
I've tried the following, but the resulting file is still an ELF and not purely the section content.
$ objcopy --only-section=<name> <infile> <outfile>
I just want the contents of ...
32
votes
2
answers
12k
views
How to interpret the output of the ldd program?
[root@wdctc1281 bin]# ldd node
linux-vdso.so.1 => (0x00007fffd33f2000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f70f7855000)
librt.so.1 => /lib64/librt.so.1 (...
29
votes
2
answers
19k
views
Recipe for compiling binutils & gcc together?
According the the gcc build instructions you can build binutils concurrently with building gcc (as well as gmp,mpc,etc).
Here's what that page says :
If you also intend to build binutils
(...
29
votes
1
answer
24k
views
What is the "__gmon_start__" symbol?
I'm compiling this code with gcc hello.c -o hello -O3:
#include <stdio.h>
int main(void) {
printf("Hello world\n");
return 0;
}
and when I list the relocations I get:
test@southpark$ ...
26
votes
3
answers
13k
views
An objcopy equivalent for Mac / iPhone?
I would like to rename symbols inside object files (.o) with something that would be the Mac equivalent of binutils' objcopy --redefine-syms tool.
I found no arm-apple-darwin10-objcopy. I tried the ...
26
votes
7
answers
2k
views
How can adding a function call cause other symbols to become undefined when linking?
I'm hoping someone will be able to help troubleshoot what I think is a linker script issue.
I'm encountering a strange problem after adding a call to a new function. Without the function call, my ...
25
votes
2
answers
10k
views
How to reverse the objcopy's strip with only-keep-debug?
In modern linux almost all objects are stripped and splitted in two parts (two files). First is executable itself and second is debug symbols, stripped out from original ELF. Such files are created ...
24
votes
3
answers
6k
views
Wrong line numbers from addr2line
I try to find the exact line of a call in the backtrace in C++ program. Right now I am using these lines (from the man page of backtrace) to get the trace:
void *bt_buffer[1000];
char **...
23
votes
2
answers
11k
views
When to use --dynamic option in nm
Sometimes when I do nm on a .so file (for example, libstdc++.so.6), it says no symbols, and I need to use nm --dynamic. But for some other .so files, I can see the symbols without --dynamic.
The ...
21
votes
4
answers
15k
views
How to link a gas assembly program that uses the C standard library with ld without using gcc?
As an exercise to learn more precisely how c programs work and what minimum level of content must exist for a program to be able to use libc, I've taken it upon myself to attempt to program primarily ...
21
votes
1
answer
14k
views
What is the difference between ar/nm and gcc-ar/gcc-nm?
ar, nm, and ranlib are provided by the binutils package. gcc-ar, gcc-nm, and gcc-ranlib are provided by the GCC package. I read somewhere that the gcc-ar, gcc-nm, and gcc-ranlib are "effectively ...
21
votes
1
answer
9k
views
Does the order of -l and -L options in the GNU linker matter?
The -l option tells the linker to search the libraries in the standard dirs.
And with -L, we can specify our own library directories for searching.
Question: Does the sequence of order matters for ...
20
votes
5
answers
7k
views
Is there an option to GNU ld to omit -dynamic-linker (PT_INTERP) completely?
I'm experimenting with the concept of pure-static-linked PIE executables on Linux, but running into the problem that the GNU binutils linker insists on adding a PT_INTERP header to the output binary ...
20
votes
3
answers
28k
views
How to see what version of Binutils is on Ubuntu?
I have searched, but not found an option that tells me what version of binutils I have on My Ubuntu. Or at least I don't know how to interpret it.
gcc -v - tells nothing about binutils
ld -v - ...
18
votes
3
answers
7k
views
How does gcc find as, ld and other binutils executables?
Is their location hardcoded into gcc code or does gcc just call as and we must have as location in our PATH variable?
And in the latter case, how could we create two completely separate gcc ...
17
votes
1
answer
74k
views
How to use/install GNU binutils (objdump)
I need to use the objdump and readelf commands in my application that runs on windows. I know I can install cygwin in order to use them. The reason why I don't want to use cygwin is because I want to ...
16
votes
1
answer
26k
views
Requirements to use flto
If I want to compile my project with -flto is it enough to have built gcc with --enable-gold or do I also need to build gold and replace ld with it? And do I need any other flags? Ie I'm doing this
...
15
votes
2
answers
8k
views
How to deal with recursive dependencies between static libraries using the binutils linker?
I'm porting an existing system from Windows to Linux. The build is structured with multiple static libraries. I ran into a linking error where a symbol (defined in libA) could not be found in an ...
15
votes
1
answer
7k
views
Injecting sections into GNU ld script; script compatibility between versions of binutils.
I'm building something like in the question How to collect data from different .a files into one array? How to keep sections in .a files with ld script?, i.e. arrays composed during link-time out of ...
15
votes
2
answers
21k
views
unable to compile: unrecognized relocation 0x2a in section text
I have received an error message when compiled "make"
$ make
g++ -fopenmp -o lang.test main.o -I../../../include/Lheader -I../../../include -L../../../lib/ -llmi -lblas -lboost_regex -lpthread -...
15
votes
1
answer
7k
views
binutils/bfd.h wants config.h now?
I'm trying to use the BFD library, and so I've installed package binutils-dev and have included:
#include <bfd.h>
and am calling bfd_openr and bfd_close and so on from my code.
Recently I ...
14
votes
1
answer
4k
views
Why do STM32 gcc linker scripts automatically discard all input sections from these standard libraries: libc.a, libm.a, libgcc.a?
From the bottom of any auto-generated STM32CubeMx-generated linker script:
/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}
From the ...
14
votes
1
answer
17k
views
GNU Linker: ELF has a LOAD segment with RWX permissions. Embedded ARM project
I have updated my arm-none-eabi GCC and the associated tools and rebuilt an embedded project I develop.
$ arm-none-eabi-ld --version
GNU ld (GNU Binutils) 2.39
Suddenly, I'm getting the warning
/usr/...
13
votes
2
answers
7k
views
How to determine which command line options gcc passes to ld by default?
Consider the hello world C program:
hello.c:
#include "stdio.h"
int main()
{
printf("Hello, World!\n");
}
If I call:
$ gcc -c hello.c -o hello.o
It will produce an ELF Relocatable File ...
13
votes
2
answers
11k
views
Difference between nm and objdump
Looking at the manuals, objdump and nm have overlapping features.
When would you use each one? What was the original purpose of each command?
13
votes
2
answers
4k
views
Building a two-part firmware image using GCC toolchain
I have some firmware built with GCC that runs on an ARM Cortex M0 based microcontroller. The build currently generates a single binary image that can be written into the program memory of the ...
12
votes
1
answer
3k
views
Why were GNU binutils and GDB merged as one package?
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git
See, especially, the tags section.
What was the rationale behind this decision? Does the merge affect the suggested way to build latest ...
12
votes
3
answers
6k
views
How to get instruction information from libopcodes?
I am writing a tool which uses libbfd and libopcodes in x86-32 and x86-64 Linux to perform disassembly. The problem is that whilst I am able to get libopcodes to disassemble, I am unable to get any ...
12
votes
1
answer
9k
views
Is the ELF .notes section really needed?
On Linux, I'm trying to strip a statically linked ELF file to the bare essentials. When I run:
strip --strip-unneeded foo
or
strip --strip-all foo
The resulting file still has a fat .notes ...
12
votes
1
answer
7k
views
How to create stub shared libraries on Linux
Let's first explain what I mean with a stub shared library: a shared library that can be used to link against (w/ a certain interface provided by a real library) but don't contain the actual code (so ...
11
votes
1
answer
3k
views
Unresolvable `R_X86_64_NONE` relocation
I'm using Devtoolset-7 on CentOS 7 and have built Boost 1.65.1 w/ it.
But when I link my application, I've got the following:
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: /opt/...
10
votes
2
answers
15k
views
How to install gnu ld on mac os x 10.6?
I'm having a lot of trouble compiling the otherwise excellent Contiki OS on my macbook pro (with mac os x 10.6). Contiki actually uses a lot of GNU-specific features and options of GCC, AR, LD, and so ...
10
votes
2
answers
2k
views
binutils build fails because of pex-unix file
I want to cross-compile GCC. I am using MSYS2 as a shell, and mingw-w64 as the compiler.
I have downloaded binutils-2.25 and I configure with:
../binutils/./configure --target=sh3eb-elf --prefix=C:/...
10
votes
2
answers
10k
views
How can the --add-section switch of OBJCOPY be used?
There are really two questions that revolve around the use of --add-section. The simple one is in the title. Based on my reading, I haven't been able to figure out how one could execute --add-...
10
votes
2
answers
14k
views
objdump and ARM vs Thumb
I'm trying to disassemble an object built for ARM with gcc. Unfortunately, objdump is trying to guess whether the code is ARM and Thumb, and is getting it wrong: it thinks my code is Thumb when it's ...
9
votes
1
answer
5k
views
Weird MIPS assembler behavior with jump (and link) instruction
So, we're studying MIPS architecture at school and we're implementing a MIPS32 architecture. I thought I'd use GNU cross-binutils as assembler but I'm getting weird output when dealing with ...
9
votes
2
answers
9k
views
gnu ld/gdb: separate debug files. How to produce the debug file when there's too much debug info to link?
There's now gdb and binutils support for separating debug info from the binaries to be debugged. Docs describing this can be found in:
gdb: separate debug files
objcopy --add-gnu-debuglink, --only-...
9
votes
3
answers
8k
views
Patching code/symbols into a dynamic-linked ELF binary
Suppose I have an ELF binary that's dynamic linked, and I want to override/redirect certain library calls. I know I can do this with LD_PRELOAD, but I want a solution that's permanent in the binary, ...
9
votes
1
answer
3k
views
How to build GCC 4.8.x on Mac OS X host for MIPS target
I am trying to build GCC / binutils for a MIPS target platform on a Mac OS X host running (10.9) x86_64. I have downloaded the latest version of binutils and GCC to my knowledge, and I have also ...
9
votes
3
answers
15k
views
How to compile an assembly file to a raw binary (like DOS .com) format with GNU assembler (as)? [duplicate]
I want to compile this source code in Windows (It just an example):
start:
NOP
NOP
When I compile it with NASM or FASM, output file length is 2 bytes. But when I compile it with GNU assembler (as) ...
9
votes
2
answers
5k
views
Linker failed: .gnu.linkonce.t
I'm having trouble linking a shared library using GCC 3.2.3 with binutils 2.18. When I try to link the library I get the following error:
.gnu.linkonce.t_... referenced in section .rodata: defined in ...
8
votes
2
answers
3k
views
ELF Dynamic loader symbol lookup ordering
What is the search order for symbol lookup when resolving dynamic relocations?
When resolving symbols for a shared library does the loader first search in the 'main executable' (to let the main ...
8
votes
1
answer
10k
views
Binutils stat illegal option -c
I use stat two times in my script once to find the file files permissions and once to find the size of the file.
`stat -c %A "$directory/$file"`
`stat -c %s "$directory/$file"`
I am using OSX 10.7 ...
8
votes
1
answer
5k
views
Is accessing the "value" of a linker script variable undefined behavior in C?
The GNU ld (linker script) manual Section 3.5.5 Source Code Reference has some really important information on how to access linker script "variables" (which are actually just integer ...
8
votes
2
answers
5k
views
List of targets supported by binutils
I am following a website ( http://wiki.osdev.org/GCC_Cross-Compiler ) to learn how to cross compile some code for different architectures. So, the first step is to download and compile Binutils for a ...
8
votes
2
answers
15k
views
Glibc vs GCC vs binutils compatibility
Is there a sort of official documentation about version compatibility between binutils, glibc and GCC? I found this matrix for binutils vs GCC version compatibility. It would be good to have something ...
8
votes
1
answer
5k
views
how to determine object code size on Linux when "size" gives the wrong answer?
I want to know precisely how much object code is generated by GCC for each of a collection of compilation units, but I'm having an odd problem where the "size" command from binutils is not giving the ...
8
votes
0
answers
3k
views
How to Strip A Symbol in Relocation
i try to remove a symbol from object file as below:
gcc -c test.c
strip --strip-symbol=test_sym test.o test.o
test_sym is a function implemented in test.c.
strip returns following message :
...