gcc

How does gcc push local variables on to the stack?

送分小仙女□ 提交于 2021-02-19 08:54:30
问题 void f () { int a[1]; int b; int c; int d[1]; } I have found that these local variables, for this example, are not pushed on to the stack in order. b and c are pushed in the order of their declaration, but, a and d are grouped together. So the compiler is allocating arrays differently from any other built in type or object. Is this a C/C++ requirement or gcc implementation detail? 回答1: The C standard says nothing about the order in which local variables are allocated. It doesn't even use the

gcc inline assembly behave strangely

主宰稳场 提交于 2021-02-19 08:25:11
问题 I am learning GCC's extended inline assembly currently. I wrote an A + B function and wants to detect the ZF flag, but things behave strangely. The compiler I use is gcc 7.3.1 on x86-64 Arch Linux. I started from the following code, this code will correctly print the a + b . int a, b, sum; scanf("%d%d", &a, &b); asm volatile ( "movl %1, %0\n" "addl %2, %0\n" : "=r"(sum) : "r"(a), "r"(b) : "cc" ); printf("%d\n", sum); Then I simply added a variable to check flags, it gives me wrong output. int

Extracting archive file in linker script

ぐ巨炮叔叔 提交于 2021-02-19 06:47:06
问题 I am trying to deal with a problem like the following one: Assume that I have a library libxyz.a created from: /* main.c */ int main(void) { int a; } compiled and archived with: gcc -c main.c -o abc.o && ar cr libxyz.a abc.o How do I have to write linker script in order to put abc.o exactly where it is expected to be? I was trying to handle it in such way: /* script.ld */ SEARCH_DIR(.) INPUT(-lxyz) SECTIONS { .text : { xyz:abc(.text) } .data : { xyz:abc(.data) } .bss : { xyz:abc(.bss) } } but

GCC placing register args on the stack with a gap below local variables?

烂漫一生 提交于 2021-02-19 06:22:28
问题 I tried to look at the assembly code for a very simple program. int func(int x) { int z = 1337; return z; } With GCC -O0, every C variable has a memory address that's not optimized away, so gcc spills its register arg: (Godbolt, gcc5.5 -O0 -fverbose-asm) func: pushq %rbp # movq %rsp, %rbp #, movl %edi, -20(%rbp) # x, x movl $1337, -4(%rbp) #, z movl -4(%rbp), %eax # z, D.2332 popq %rbp # ret What is the reason that the function parameter x gets placed on the stack below the local variables?

GCC placing register args on the stack with a gap below local variables?

为君一笑 提交于 2021-02-19 06:22:26
问题 I tried to look at the assembly code for a very simple program. int func(int x) { int z = 1337; return z; } With GCC -O0, every C variable has a memory address that's not optimized away, so gcc spills its register arg: (Godbolt, gcc5.5 -O0 -fverbose-asm) func: pushq %rbp # movq %rsp, %rbp #, movl %edi, -20(%rbp) # x, x movl $1337, -4(%rbp) #, z movl -4(%rbp), %eax # z, D.2332 popq %rbp # ret What is the reason that the function parameter x gets placed on the stack below the local variables?

CMake cannot generate a safe linker search path - yocto 2.4

孤人 提交于 2021-02-19 06:05:24
问题 I have 2 yocto pkgs that can be successfully compiled with gcc 5.4, cmake 3.6.1 on yocto 2.0.2 but I'm facing the following issue with: gcc 6.3, cmake 3.6.1 on yocto 2.4 . After some research, I observed that yocto changed the sysroot structure (sysroot per package instead of a common sysroot). The error looks like this: CMake Warning at src/mytest/CMakeLists.txt:71 (add_executable): Cannot generate a safe linker search path for target mytest because files in some directories may conflict

Installing Ta-lib creates gcc error

非 Y 不嫁゛ 提交于 2021-02-19 05:28:24
问题 I am getting gcc error when trying to install Ta-lib as a global package on my mac. I get an error below: gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I//anaconda/include -arch x86_64 -I//anaconda/include -arch x86_64 -I//anaconda/lib/python3.6/site-packages/numpy/core/include -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I//anaconda/include/python3.6m -c talib/common.c -o build/temp.macosx-10.7-x86_64-3

Getting GCC/Clang to use CMOV

本小妞迷上赌 提交于 2021-02-19 04:38:05
问题 I have a simple tagged union of values. The values can either be int64_ts or doubles . I am performing addition on the these unions with the caveat that if both arguments represent int64_t values then the result should also have an int64_t value. Here is the code: #include<stdint.h> union Value { int64_t a; double b; }; enum Type { DOUBLE, LONG }; // Value + type. struct TaggedValue { Type type; Value value; }; void add(const TaggedValue& arg1, const TaggedValue& arg2, TaggedValue* out) {

Eliminating instantiation of useless destructor calls?

浪尽此生 提交于 2021-02-19 04:08:35
问题 Well, my colleague is pretty in depth nitpicking about eliminating unnecessarily code instantiations for destructor functions. Still same situation, as mentioned in this question: Very limited space for .text section (less 256 KB) Code base should scale among several targets, including the most limited ones Well known use cases of the code base by means some destructor logic is neccesary to manage object lifetimes or not (for many cases life-time of objects is infinite, unless the hardware is

gcc doesn't accept out-of-line definition of member with non-type template parameter defined via nested templated using clause

戏子无情 提交于 2021-02-19 04:07:51
问题 The title seems convoluted but our test-case is actually a minimal example for a real case. We have code for which we want to choose implementation of a method based on the template parameter. We during clean up we defined conditional enable_if_t with using clause, and as next step wanted to put definition out of line, this produced following code: #include <type_traits> #include <iostream> #include <string> template <typename T> struct A { template <typename U> using is_int_or_float = std: