ld

Solution needed for building a static IDT and GDT at assemble/compile/link time

南楼画角 提交于 2019-12-17 20:24:09
问题 This question is inspired by a problem many have encountered over the years, especially in x86 operating system development. Recently a related NASM question was bumped up by an edit. In that case the person was using NASM and was getting the assemble time error: shift operator may only be applied to scalar values Another related question asks about a problem with GCC code when generating a static IDT at compile time that resulted in the error: initializer element is not constant In both

Use ld on 64-bit platform to generate 32-bit executable

拈花ヽ惹草 提交于 2019-12-17 19:46:40
问题 I wrote an assembly that is assemble with: $as --32 -o hello.o hello.s Then I tried to generate an executable with: $ld -o hello hello.o It gives me an error: ld: i386 architecture of input file `ConditionalBranching.o' is incompatible with i386:x86-64 output I tried using flag -m32 or --32, but ld dont take them. I cannot find a solution by reading the man page of ld. How can I generate a 32-bit binary from my 32-bit shared object? 回答1: Your linker is attempting to create a 64-bit binary,

What does KEEP mean in a linker script?

爱⌒轻易说出口 提交于 2019-12-17 10:57:08
问题 The LD manual does not explain what the KEEP command does. Below is a snippet from a third-party linker script that features KEEP . What does the KEEP command do in ld ? SECTIONS { .text : { . = ALIGN(4); _text = .; PROVIDE(stext = .); KEEP(*(.isr_vector)) KEEP(*(.init)) *(.text .text.*) *(.rodata .rodata.*) *(.gnu.linkonce.t.*) *(.glue_7) *(.glue_7t) *(.gcc_except_table) *(.gnu.linkonce.r.*) . = ALIGN(4); _etext = .; _sidata = _etext; PROVIDE(etext = .); _fini = . ; *(.fini) } >flash 回答1:

How to force gcc to link an unused static library

时光总嘲笑我的痴心妄想 提交于 2019-12-17 04:27:55
问题 I have a program and a static library: // main.cpp int main() {} // mylib.cpp #include <iostream> struct S { S() { std::cout << "Hello World\n";} }; S s; I want to link the static library ( libmylib.a ) to the program object ( main.o ), although the latter does not use any symbol of the former directly. The following commands do not seem to the job with g++ 4.7 . They will run without any errors or warnings, but apparently libmylib.a will not be linked: g++ -o program main.o -Wl,--no-as

How to print the ld(linker) search path

无人久伴 提交于 2019-12-17 02:25:34
问题 What is the way to print the search paths that in looked by ld in the order it searches. 回答1: You can do this by executing the following command: ld --verbose | grep SEARCH_DIR | tr -s ' ;' \\012 gcc passes a few extra -L paths to the linker, which you can list with the following command: gcc -print-search-dirs | sed '/^lib/b 1;d;:1;s,/[^/.][^/]*/\.\./,/,;t 1;s,:[^=]*=,:;,;s,;,; ,g' | tr \; \\012 The answers suggesting to use ld.so.conf and ldconfig are not correct because they refer to the

LFS 7.2 glibc-2.16.0 make error

∥☆過路亽.° 提交于 2019-12-13 21:53:23
问题 I'm building an LFS system ( refering to LFS 7.2 ) I got this make error while building glibc-2.16.0: /mnt/lfs/tools/bin/../lib/gcc/i686-lfs-linux-gnu/4.7.1/../../../../i686-lfs-linux-gnu/bin/ld: cannot find -lgcc_s collect2: error: ld returned 1 exit status make[2]: *** [/mnt/lfs/sources/glibc-build/iconv/iconvconfig] Error 1 make[2]: Leaving directory `/mnt/lfs/sources/glibc-2.16.0/iconv' make[1]: *** [iconv/others] Error 2 make[1]: Leaving directory `/mnt/lfs/sources/glibc-2.16.0' make: **

Why does changing the linking order fix some linking errors on one system?

為{幸葍}努か 提交于 2019-12-13 17:50:22
问题 So I had this strange behavior with GitLab CI. I got it working but now I am wondering why it works. First of all I was starting with GitLab CI. I got a local runner with docker on my machine (Arch Linux), so that I can test without pushing and waiting. I wrote a test with the googletest framework (Just an assert true). I triggered the script locally and everything worked. All tests passed in the local docker image. So now, when everything was working, I pushed to the repository and a runner

Getting the value of *ABS* symbols from C

点点圈 提交于 2019-12-13 17:26:02
问题 What is the proper way of accessing the actual value of an *ABS* (absolute, not-to-be-relocated) symbol from C? I'm using ld to embed data (... a HTML template) in an executable (... following the method described in https://csl.name/post/embedding-binary-data/). As in: ld -r -b binary [the_file_to_be_embedded] -o [some_object.o] Then, I'm using const char _some_object_start; const char _some_object_end; const int _some_object_size; in the actual code. The actual linked text works nicely by

Using .org directive with data in .data section: In connection with ld

穿精又带淫゛_ 提交于 2019-12-13 14:33:00
问题 In my efforts to understand how to use the GNU binutils to build a simple boot loader using gas I have come across the question, how do you tell the linker where to put your data, in a file that uses .org to advance the location counter while keeping the file size at 512 bytes. I can't seem to find a way to do this. The assembly program that tries to do this is: # Author: Matthew Hoggan # Date Created: Tuesday, Mar 6, 2012 .code16 # Tell assembler to work in 16 bit mode .section .data msg: #

C program compiling with glibc and not the default libraries: Permission denied on execution

∥☆過路亽.° 提交于 2019-12-13 13:08:50
问题 it's my first question on stackoverflow, so I will try to do it well. Context: I would like to deliver a program who could run on every Linux distribution (for example, a program who will use C++11, running on a system who don't have the C++11 library). For that I would like to copy all the libraries who are used by my program and put them in a folder with the executable, so it can use these libraries instead of the system's one. I got 2 environments to test: - Opensuse, with (GNU libc) 2.19