ld

Elegant way to set base address of ELF image with Linux binutils?

巧了我就是萌 提交于 2019-12-20 03:01:05
问题 For a personal project, I need to write an executable that loads at a non-default memory address. From this SO question, I know I can set the entry address for an ELF and modify the section addresses manually so that the executable is effectively based at some address I choose. However, the answer suggests that this is only works if I don't glibc initialization (which I need for this project), and setting section memory addresses every time I compile would be difficult (not to mention tedious

NASM: emit MSW of non-scalar (link-time) value [duplicate]

一个人想着一个人 提交于 2019-12-20 02:33:09
问题 This question already has an answer here : Solution needed for building a static IDT and GDT at assemble/compile/link time (1 answer) Closed 3 months ago . I am attempting to define a constant IDT (Interrupt Descriptor Table) entry in NASM, and to do so, I need to emit into a data table the high word of a double-word address that is not resolved until link time . Is there a way to do it? Here's the interrupt handler: ;;; Interrupt 3 (breakpoint) handler. For now, just poke the screen and halt

Linking a dynamically linked executable with ld

和自甴很熟 提交于 2019-12-20 01:52:14
问题 i'm trying to create a dynamically linked executable (elf_i386) without gcc. The program is very simple (only a printf)...here the commands: $ gcc -c simple.c $ ld -o simple -dynamic-linker /lib/ld-linux.so.2 --entry main /usr/lib/crt1.o /usr/lib/crti.o simple.o -lc /usr/lib/crtn.o The executable is created and also file command and ldd command show the right output... However when i launch the program after the call to printf i get a segmentation fault...i've examined with objdump the

G++ cannot find boost library

十年热恋 提交于 2019-12-19 19:36:13
问题 I am not good in command-line compiling. My problem is inability to compile simple project, that depends from Boost. The following is a log of my trying: $ g++ -Wall test.cpp -o main /tmp/ccCTvBYE.o: In function `__static_initialization_and_destruction_0(int, int)': test.cpp:(.text+0x6b): undefined reference to `boost::system::generic_category()' test.cpp:(.text+0x77): undefined reference to `boost::system::generic_category()' test.cpp:(.text+0x83): undefined reference to `boost::system:

ld linker removing an object file from a static library when creating a shared one

☆樱花仙子☆ 提交于 2019-12-19 09:55:58
问题 I have a number of static libraries which I link together into one shared library. One of them, say libUsefulFunc.a contains an object file usefulFunc.o with a function, usefulFunc() that is only used from another static library, let's say usingFunc(), residing in usingFunc.c hosted in libUsingFunc.a The problem is that the linker throws away the usefulFunc.o and I get error " undefined reference ". I tried both orders of linking. I've recreated the situation using the simplest files I could

Getting undefined reference to std::thread::_M_start_thread

主宰稳场 提交于 2019-12-19 08:28:34
问题 I'm building an app that uses a 3rd party lib (Box2D-MT) which I build from sources. When linking, I get this undefined reference error: b2Threading.cpp:(.text._ZNSt6threadC2IM12b2ThreadPoolFviEJPS1_iEEEOT_DpOT0_[_ZNSt6threadC5IM12b2ThreadPoolFviEJPS1_iEEEOT_DpOT0_]+0xa4): undefined reference to 'std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>, void (*)())' I am building with g++ and link with -lBox2D -lpthread -lrt -ldl -lstdc++ also, I am compiling with -std=c++11

How to locate a variable correctly in AT&T assembly?

孤街醉人 提交于 2019-12-19 08:05:59
问题 I am practicing to write a bootstrap using assembly (in AT&T syntax, and gnu/gas). The small program is assembled and linked, then copied to the first sector of a virtual disk. BIOS will load it into 0000:7c00 , and here comes the problem. The call hello will be translated from call 0010 to call 7c10 during running. But the movw $message, %as doesn't get relocated. The ax is still 0026 , not 7c26 . The result is that I can't make the Hello World on the screen. Instead, some random data at

Is there a way to ignore unused undefined references?

不问归期 提交于 2019-12-19 07:24:31
问题 Suppose I have two source files — UndefErr.cpp : #include <cstdio> void UndefFunc(); void Func2(){UndefFunc();} void Func1(){printf("Hi\n");} And the main.cpp : void Func1(); int main(){ Func1(); return 0; } As you see in the UndefErr.cpp the Func2() going to trigger an error, for it using the undefined UndefFunc() . However the main function doesn't care about the Func2() ! According to a relevant question I could pass an option --unresolved-symbols=ignore-in-object-files to the linker, but

version-script and hidden visibility

穿精又带淫゛_ 提交于 2019-12-19 05:45:05
问题 When using gcc to build a shared library, it's possible to limit the visibility of the symbols using -fvisibility=hidden . I also just learned you can limit visibility using the version-script option to ld . Now I want to know if it's possible to combine these. Say I have a program with the following: void foobar() {} void say_hello() {} Then I have the version script file with: { global: foobar; } And I compile this with: gcc -fvisibility=hidden -Wl,--version-script=<version-script> test.c

When i should use ld instead of gcc?

☆樱花仙子☆ 提交于 2019-12-19 05:38:07
问题 I want to know when i should use ld linker instead off gcc. I just wrote a simply hello world in c++, of course i include iostream library. If i want make a binary file with gcc i just use: g++ hello hello.cpp and i've got my binary file. Later i try to use ld linker. To get object file i use: g++ -c hello.cpp . Ok that was easy, but the link command was horrible long: ld -o hello.out hello.o \ -L /usr/lib/gcc/x86_64-linux-gnu/4.8.4/ \ /usr/lib/gcc/x86_64-linux-gnu/4.8.4/crtbegin.o \ /usr/lib