binutils

gdb: how does it know the variable type and size?

我与影子孤独终老i 提交于 2019-12-11 12:43:52
问题 I'm trying to figure this out as I'm trying to do the same thing (hopefully) with a home grown script: Example C code: typedef struct _B { A aa; double b; char c[LEN]; int d; char *a_ptr[10]; } B; B this_b; If I compile this with gcc -g and gdb a.out afterwards, gdb knows exactly what and where a_ptr is: (gdb) p &(this_b.a_ptr) $1 = (char *(*)[10]) 0x804a084 how does it do that? And can I do the same thing (knowing it's address and type) through other utilities? 回答1: When you build with the

Selectively suppressing glibc link warnings?

℡╲_俬逩灬. 提交于 2019-12-11 07:13:54
问题 glibc uses the following "technique" to generate link warnings... #define link_warning(symbol, msg) \ __make_section_unallocated (".gnu.warning." #symbol) \ static const char __evoke_link_warning_##symbol[] \ __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \ = msg; For a particular link warning generated by this, is there any command-line switch that can be passed to ld or gcc in order to suppress it? (For compile-time warnings you can suppress with `#pragma diagnostic

g++: as fails to determine which assembler to run

烈酒焚心 提交于 2019-12-11 04:48:39
问题 Today I wanted to recompile one of my projects. Compiling this project had already worked on my machine, but this time an error occured. The compiler output goes: fatal error: as: unknown host architecture (can't determine which assembler to run)` for the line: g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I../../.vscode -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I../../.vscode -I

GCJ Linking Error: Says error: undefined reference to 'main' collect2: error: ld returned 1 exit status

二次信任 提交于 2019-12-11 04:35:44
问题 The code is this: public class Thingy { public static void main(String[] args) { System.out.println(Math.random()); } } So, absolutely NOT an unusual case, just a basic example. When I try to use GCJ's javac implementation to make bytecode instead of the OpenJDK one, it works fine. neil@neil-Inspiron-M5030:~/javastuff$ javac Thingy.java neil@neil-Inspiron-M5030:~/javastuff$ java Thingy 0.2794511843566371 But when I try to get GCJ to make native code, I get that linker error. If you want, I

Building a cross compile of binutils on OS X Yosemite

久未见 提交于 2019-12-11 02:59:27
问题 I'm trying to build binutils for generating MIPS code on Mac OS X. I found this site (http://www.theairportwiki.com/index.php/Building_a_cross_compile_of_GCC_for_MIPS_on_OS_X) from How to build GCC 4.8.x on Mac OS X host for MIPS target, and followed the instructions. I install the gcc-4.8 from brew, and installed source code of binutils and gcc. This is the compilation option setup. $ export CC=/usr/local/bin/gcc-4.8 $ export CXX=/usr/local/bin/g++-4.8 $ export CPP=/usr/local/bin/cpp-4.8 $

Linking 32- and 64-bit code together into a single binary

廉价感情. 提交于 2019-12-10 20:53:55
问题 In a comment to this question, Unexpected behaviour in simple pointer arithmetics in kernel space C code, Michael Petch wrote, "The 64-bit ELF format supports 32-bit code sections." I have a working program that includes both 32- and 64-bit code and switches between them. I have never been able to figure out how to link compiler-generated 32- and 64-bit code together without a linker error, so all the 32-bit code is written in assembly. As the project has become more complex, maintenance of

What does SEGMENT_START(“text-segment”, 0x400000) represent?

丶灬走出姿态 提交于 2019-12-10 20:18:56
问题 I'm learning about the layout of executable binaries. My end goal is to analyze a specific executable for things that could be refactored (in its source) to reduce the compiled output size. I've been using https://www.embeddedrelated.com/showarticle/900.php and https://www.geeksforgeeks.org/memory-layout-of-c-program/ as references for this initial learning. From what I've learned, a linker script specifies the addresses where sections of compiled binaries are placed. E.g. > ld --verbose |

Is the ELF .notes section really needed?

陌路散爱 提交于 2019-12-09 17:21:27
问题 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 section that appears to be full of funky strings. Is the .notes section really needed or can I safely force it out with --remove-section? Thanks for any help. 回答1: From experience and from looking at the man page for strip , it looks like strip isn't supposed to get rid of any and all sections and strings

Patching code/symbols into a dynamic-linked ELF binary

大兔子大兔子 提交于 2019-12-09 10:37:37
问题 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, independent of the environment, and that works for setuid/setgid binaries, none of which LD_PRELOAD can achieve. What I'd like to do is add code from additional object files (possibly in new sections, if necessary) and add the symbols from these object files to the binary's symbol table so that

Why does GNU ld resolve symbols differently when linking executables vs shared objects?

巧了我就是萌 提交于 2019-12-08 17:21:04
问题 I have a trivial piece of C++ code that looks something like this: #include <boost/timer/timer.hpp> int main(void) { boost::timer::auto_cpu_timer t; return 0; } I tried to compile and link it (with gcc 4.8.1 and GNU ld 2.23.52.20130828) as follows: $ g++ -o test test.cc -lboost_timer /usr/bin/ld: /tmp/cc2jP1jv.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv' /usr/lib/libboost_system.so.1.54.0: error adding symbols: DSO missing from command line collect2: error: ld