gas

How to configure gcc to use -no-pie by default?

落花浮王杯 提交于 2019-12-23 19:40:35
问题 I want to compile the following program on Linux: .global _start .text _start: mov $1, %rax mov $1, %rdi mov $msg, %rsi mov $13, %rdx syscall mov $60, %rax xor %rdi, %rdi syscall msg: .ascii "Hello World!\n" However, it gives me the following linker error: $ gcc -nostdlib hello.s /usr/bin/ld: /tmp/ccMNQrOF.o: relocation R_X86_64_32S against `.text' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Nonrepresentable section on output collect2:

Is '.set noat' unsupported for MIPS assembly?

 ̄綄美尐妖づ 提交于 2019-12-23 18:44:51
问题 Currently, I'm learning GNU as, and find a lot useful information in "info as". I found ".set noat" is used in MIPS specified code, but when searching for this directive in "info as", I found its explanation in node "alpha directive", but not in "MIPS Dependent Features". Why? did I miss something in the manual? TIA 回答1: The .set at/noat is a valid construction for MIPS architecture and works the similar way as on Alpha by disabling/enabling warning when $at register is used by user. As

how do you make an x86 assembly program in linux that converts files to uppercase?

帅比萌擦擦* 提交于 2019-12-23 17:40:18
问题 I found a pdf file called: ProgrammingGroundUp-1-0-booksize.pdf, and one of the projects is to make an assembly program that takes in files and converts them to uppercase, ` .section .data #######CONSTANTS######## #system call numbers .equ SYS_OPEN, 5 .equ SYS_WRITE, 4 .equ SYS_READ, 3 .equ SYS_CLOSE, 6 .equ SYS_EXIT, 1 #options for open (look at #/usr/include/asm/fcntl.h for #various values. You can combine them #by adding them or ORing them) #This is discussed at greater length #in

64-bit GCC mixing 32-bit and 64-bit pointers

▼魔方 西西 提交于 2019-12-23 09:59:06
问题 Although the code works, I'm baffled by the compiler's decision to seemingly mix 32 and 64 bit parameters of the same type. Specifically, I have a function which receives three char pointers. Looking at the assembly code, two of the three are passed as 64-bit pointers (as expected), while the third, a local constant, but character string nonetheless, is being passed as a 32-bit pointer. I don't see how my function could ever know when the 3rd parameter isn't a fully loaded 64-bit pointer.

How do I assemble GAS assembly and link it with the Open Watcom C library?

限于喜欢 提交于 2019-12-23 08:46:57
问题 I am trying to produce 16-bit DOS executables, but using the gcc compiler. So I am using the ancient gcc-4.3 ia16 port. I made a Docker image of my build: https://registry.hub.docker.com/u/ysangkok/ia16-gcc-rask Here's what I am trying: host $ mkdir results host $ docker run -v $PWD/results:/results -it ysangkok/ia16-gcc-rask container $ cd results I don't include the header, cause gcc can't use OpenWatcom's libc headers. container $ echo 'main() { printf("lol"); }' > test.c I don't link

GCC Assembly Optimizations - Why are these equivalent?

拥有回忆 提交于 2019-12-22 03:58:43
问题 I am trying to learn how assembly works at an elementary level and so I have been playing with the -S output of gcc compilations. I wrote a simple program that defines two bytes and returns their sum. The entire program follows: int main(void) { char A = 5; char B = 10; return A + B; } When I compile this with no optimizations using: gcc -O0 -S -c test.c I get test.s that looks like the following: .file "test.c" .def ___main; .scl 2; .type 32; .endef .text .globl _main .def _main; .scl 2;

“Invalid symbol redefinition” in inline ASM on LLVM

一曲冷凌霜 提交于 2019-12-21 21:55:52
问题 I've got a project in Xcode (4.5.2) that builds fine using the Debug configuration. However, now that I've switched to building the Release configuration, I'm getting an issue: one of my inline assembly functions is getting the error Invalid symbol redefinition . Googling that error message finds me a few people who have got that compiler error, but no information as to what it means. Here's the function, with the error lines annotated: inline int MulDivAdd(int nNumber, int nNumerator, int

calling assembly functions from c

只愿长相守 提交于 2019-12-20 09:48:50
问题 I'm trying to use a function in assembly, invoked from a C project. This function is supposed to call a libc function let's say printf() , but I keep getting a segmentation fault. In the .c file I have the declaration of the function let's say int do_shit_in_asm() In the .asm file I have .extern printf .section .data printtext: .ascii "test" .section .text .global do_shit_in_asm .type do_shit_in_asm, @function do_shit_in_asm: pushl %ebp movl %esp, %ebp push printtext call printf movl %ebp,

Why doesn't this attempt at using sys_write do anything?

喜你入骨 提交于 2019-12-20 04:38:39
问题 Here it is: .SECTION .data msg: .string "AAAA" .SECTION .text .globl _start _start: mov $1, %rax mov $1, %rdi mov msg, %rsi mov $4, %rdx syscall Not only does this code not segfault, it also outputs nothing. According to what I've read, a program should call sys_exit, or it would segfault, but this does not happen. 回答1: mov msg, %rsi This instruction will interpret the data at "msg" as 64-bit value and load that value into the register rsi . The instruction does NOT load the address of "msg"

Assembling i386 code on x86_64

…衆ロ難τιáo~ 提交于 2019-12-20 02:56:05
问题 The following code does not work as expected: .intel_syntax noprefix .arch i386 .data hello_world: .ascii "Hello world!\n" hello_world_end: .equ hello_world_len, hello_world_end - hello_world .text .global _start _start: mov ebx, 1 mov ecx, hello_world mov edx, hello_world_len mov eax, 4 int 0x80 mov ebx, 0 mov eax, 1 int 0x80 When ran through: as test.s -o test.o ld test.o -o test ./test It outputs nothing. When I change the line: mov ecx, offset hello_world ; added offset It works fine. I