gcc

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:34
问题 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:

Eliminating instantiation of useless destructor calls?

时间秒杀一切 提交于 2021-02-19 04:06:08
问题 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

Linking error: selective static linking of libm.a in GCC

浪尽此生 提交于 2021-02-19 03:52:28
问题 I want to selectively link libm.a statically, all the other libraries ( libc.so included) dinamically. But if I use the math functions from math.h , it almost always fails to link correctly. Why? And why does it work sometimes? (For example if I only use sqrt , fabs or, strangely, tanh , it seems to link correctly) myscript.sh: #!/bin/bash for i in sqrt tanh sin tan do echo "-----$i----------" sed "s/ciao/$i/" prova.c >provat.c gcc provat.c -fno-builtin -l:libm.a [[ $? -eq 0 ]] && { echo -n "

Reason and solution for error -“/usr/bin/ld: cannot find -levent ”?

一曲冷凌霜 提交于 2021-02-19 03:36:27
问题 While compiling my program which is using libevent library I am using gcc option -levent. But I am getting this error - /usr/bin/ld: cannot find -levent I do not have libevent on my system so I am statically linking to it while compiling using gcc -o Hello -static -I libevent-1.4.12-stable/ hello.c -levent How can i resolve this? Thanks in advance! 回答1: Where is the libevent.(a|so) file on your system? If it isn't on your system's library path then you will have to add a -L option adding its

optimizing array loop in c

孤街醉人 提交于 2021-02-19 02:38:19
问题 I have looked online and in my books but I can't seem to get this. I was asked to optimize a small part of a program. Specifically to take an array and add its contents within a small amount of time, with vi and gcc, without using the built-in optimizer. I have tried loop unrolling and a couple of other optimizations meant for products. Can you please help? int length = ARRAY_SIZE; int limit = length-4; for (j=0; j < limit; j+=5) { sum += array[j] + array[j+1] + array[j+2] + array[j+3] +

Linking with another start-up file

你说的曾经没有我的故事 提交于 2021-02-19 02:37:09
问题 I am trying to link a program with my own start-up file by using the STARTUP directive in a LD script: ... ENTRY(_start) STARTUP(my_crt1.o) ... GCC driver is used to link the program (not to bother with library paths like libgcc, etc.): gcc -T my_script.ld ... Unfortunately, it only works with a GCC compiled for powerpc targets, while arm or i686 targets don't and still include crt0.o in collect2. For example: arm-eabi-g++ -v -T my_script.ld ... gives me: collect2 ... /opt/lib/gcc/arm-eabi/4

compiling glibc from source with debug symbols

时间秒杀一切 提交于 2021-02-19 02:27:08
问题 I need to compile glibc from source with debug symbols . 1.Where do i specify the '-g' option for this 2.How do i later make a sample code link to this particular glibc rather than the one installed on my system? 回答1: I need to compile glibc from source with debug symbols You will have hard time compiling glibc without debug symbols. A default ./configure && make will have -g on compile line. How do i later make a sample code link to this particular glibc rather than the one installed on my

gcc canaries : undefined reference to __stack_chk_guard

巧了我就是萌 提交于 2021-02-18 22:16:52
问题 I'm trying to enable gcc' s canaries' generation but I get an undefined reference to __stack_chk_guard. From gcc's man about canaries : -mstack-protector-guard=guard Generate stack protection code using canary at guard. Supported locations are global for global canary or tls for per-thread canary in the TLS block (the default). This option has effect only when -fstack-protector or -fstack-protector-all is specified. These -m switches are supported in addition to the above on x86-64 processors

Stack alignment on x86

有些话、适合烂在心里 提交于 2021-02-18 21:12:17
问题 I had a mysterious bus error that occurred, on a x86 (32-bit) platform, when running code compiled with gcc-4.8.1 with -march=pentium4 . I traced the problem to an SSE instruction: movdqa %xmm5,0x50(%esp) with esp = 0xbfffedac. movdqa requires the address to be 16-byte aligned, which is not the case here, thus the bus error. The problem does not occur if compiling with -march=native (this is a Core-i3 processor). As far as I know, the only stack alignment guaranteed on Linux/x86 is 4-byte.

Why does GCC use mov/mfence instead of xchg to implement C11's atomic_store?

那年仲夏 提交于 2021-02-18 20:56:35
问题 In C++ and Beyond 2012: Herb Sutter - atomic<> Weapons, 2 of 2 Herb Sutter argues (around 0:38:20) that one should use xchg , not mov / mfence to implement atomic_store on x86. He also seems to suggest that this particular instruction sequence is what everyone agreed one. However, GCC uses the latter. Why does GCC use this particular implementation? 回答1: Quite simply, the mov and mfence method is faster as it does not trigger a redundant memory read like the xchg which will take time. The x86