42,278 questions
0
votes
1
answer
54
views
Unfreeable Memory when Using Capstone
I disassembled a 7,838,304-Byte portion of /usr/lib/x86_64-linux-gnu/dri/i965_dri.so using Capstone as shown below:
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#...
1
vote
0
answers
54
views
Recommended RStan compiler flags for gcc
I need to install RStan and I want to make sure that it's as efficient as possible. I'm using gcc. I'm reading this guide from 2022.
Luckily, the Stan developers built an option called STAN_CPP_OPTIMS
...
11
votes
1
answer
619
views
constexpr self-referencing struct
Consider the following simplified code:
template <class T> class Foo {
T t;
const T* t_ptr;
public:
constexpr Foo(T t): t(t), t_ptr(&this->t) {}
constexpr Foo(const Foo&...
1
vote
0
answers
88
views
interrupt(): gate descriptor is not valid sys seg (vector=0x0X)
I am making my own UNIX like OS called Connor's UNIX and I am implementing kernel and userspace separation and I have been all day and this is as far as I can get it to work and if you need any more ...
-1
votes
0
answers
67
views
i686-elf-gcc "Error: invalid instruction suffix for 'push'/'pop'" [closed]
I'm following the barebones guide on OSDev Wiki and I'm trying to compile my kernel.c file with
i686-elf-gcc -ffreestanding -O2 -m32 -c kernel.c -o kernel.o
but I constantly get the following ...
3
votes
2
answers
105
views
Handling Buffer Size Errors in strftime: ERANGE vs EOVERFLOW
I have an application where I need to generate date and time based on the locale using the strftime function provided by C's time.h:
#include <stdio.h>
#include <time.h>
#include <...
2
votes
0
answers
44
views
Best way to successfully compile GNU-pth as a 32-bit dynamic library under Linux?
Regardless of --build or --target, when configure points out the
I'm trying to compile GNU pth in 32-bits form under Linux.
Toolchain used:
Ubuntu 24.04.2 (VM)
gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13....
Advice
0
votes
4
replies
184
views
Why does GCC transform a >= 4 into a > 3 at -O0? JG seems to be more complex than JGE
Title: Why does GCC transform a >= 4 into a > 3 at -O0? JG seems more complex than JGE
I'm analyzing a simple C code on godbolt and found GCC's code generation puzzling:
long a;
a = a >= 4;
...
Tooling
0
votes
0
replies
42
views
How do you set up GCC for Windows with the Windows 10 SDK?
A friend of mine has an application in C he has been helping to maintain, which he has been building for Linux, but he asked me to help build Windows binaries. The project has a Makefile.win32, so it ...
Advice
0
votes
1
replies
42
views
Adding stack information to jit'd code for sanitization
Disclaimer: I'm expecting that the answer to this question will be that it can't be done, but I'm asking as a just in case.
I am working on a JIT'd language with the compiler and runtime implemented ...
Tooling
0
votes
3
replies
98
views
Which IDE and tools for gcc C development?
Which IDE and tools are best suited for gcc C development? I currently use vscode and the tried using the ms-vscode.cpptools extension which "supports" gcc C. But extensions like nested ...
Advice
2
votes
6
replies
121
views
determine cpu after c++ compilation with gcc?
Does anyone know if there is, in c++, any way to determine at runtime the cpu characteristics of the machine that compiled the code? For example, in gcc (which I'm using) the preprocessor variable ...
Advice
0
votes
6
replies
80
views
object file is twice larger than expected
I have a AVR GCC toolchain compiled to work on aarch64-linux-gnu devices (ARM64) and it produced twice larger file (around 35Kb) than almost identical command-line on desktop (mac silicon, around 20Kb)...
3
votes
1
answer
119
views
std::filesystem::path::parent_path() GCC vs Clang behavior with multiple leading separators
I stumbled upon different behavior of std::filesystem::path::parent_path() when a path contains leading slashes. Clang says that the parent of ///a is /// (which is what I would expect), but GCC says ...
1
vote
2
answers
149
views
Different handling of signed value between MSVC and GCC
Take the below piece of code, that simply Trims a string, removing whitespace characters from either end:
const std::string TrimString(const std::string& s)
{
const auto iter = std::find_if(s....
3
votes
2
answers
190
views
Why do GCC and Clang fail to auto-vectorize simple loop?
I have two functions counting the occurrences of a target char in the given input buffer. The functions vary only in how they communicate the result back to the caller; one returns the result and the ...
0
votes
0
answers
40
views
Why DW_AT_language is C11 for -std=c17 (and higher)?
For -std=c17 (and higher) DW_AT_language is C11:
$ echo "int x;" | gcc -c -xc - -fPIC -o x.o -g -std=c17
$ gcc -shared -o x.so x.o
$ readelf x.so -w | grep -P '(DW_AT_language\s*:|DWARF ...
0
votes
1
answer
105
views
Linking fails with: in function `main.cold': undefined reference to `__cxa_call_terminate'
I'm trying to build, using CMake, a program involving C++ and CUDA-C++ code. It used to build file, several months ago, but - now am getting a linker error I'm not familiar with:
in function `main....
1
vote
0
answers
90
views
Avoid non standard transitive includes in gcc / libstdc++ [duplicate]
The following code compiles in gcc15 with g++ -std=c++17
#include <iostream>
int main() {
int A, B;
std::cin >> A >> B;
auto v = std::tie(A, B);
}
However, this is ...
0
votes
2
answers
84
views
gcc/g++ compiler with POSIX thread model
I'm on Windows OS and in the past month I used to compile a C/C++ project in Qt Creator IDE using MinGW's gcc/g++ compilers based on POSIX thread model, i.e. compilers that were built with the option -...
Advice
0
votes
8
replies
144
views
Is it possible to package binary data inside the binary without having it in memory?
I recently learned about C23's implementation for #embed, so I was wondering if I can use that with extern in a c++23 program/game to have all 3d models and assets baked into the exe but not in memory ...
0
votes
1
answer
20
views
Getting address of special symbols in stripped ELF
I have a program targeting a small memory ARM R5 CPU, being compiled with gcc 11.2.0 and ld 2.37.20210721.
I have a critical symbol that I would like to know the address of, even if the binary was ...
6
votes
0
answers
143
views
Optimized Assembly Generation for Unsigned Multiplication Leads to Unexpected Result for Cortex-M0+
I was experimenting with some fixed-point arithmetic on the Cortex-M0+ in Godbolt's compiler explorer and came across an interesting behaviour with respect to the optimisation of a multiplication ...
0
votes
1
answer
52
views
Linkage of Win32 api and custom GCC build (StrawberryPerl)
I try to build some source code containig Win32 API code with GCC 8.3.0 (i686-posix-dwarf) that comes with Strawberry Perl Portable package. It easily builds code, but struggles when it comes to ...
Best practices
2
votes
10
replies
288
views
How to tell the C compiler that data pointed to by a pointer won't be constantly modified by another thread after being passed to a function?
In C, when I pass a pointer to a function, the compiler always seems to assume that the data pointed to by that pointer might be continuously modified in another thread, even though in actual API ...
4
votes
1
answer
95
views
Why is attribute noinline ignored by gcc-15.1.0 in this example?
Looking at this benchmark about a custom std::function implementation: https://github.com/PacktPublishing/Hands-On-Design-Patterns-with-CPP-Second-Edition/blob/main/Chapter06/09_function.C
I tried to ...
Advice
2
votes
10
replies
395
views
Visual studio vs gcc
I'm a small-scale C programmer at the moment, and I'm bugged by the question: is Visual Studio worth the annoyance that it is?
I've been programming in C and C++ in Visual Studio Code for a while, and ...
4
votes
0
answers
412
views
Why does a simple C++ const array loop break GCC 11.2 assembly output on Compiler Explorer, but not GCC 15 or MSVC/ICX?
I've been investigating the assembly output for a simple C++ loop involving a const array and const size, and I've encountered peculiar version-specific behavior with GCC on Compiler Explorer.
My ...
2
votes
3
answers
100
views
different behaviour of objcopy with binary output between Windows and Linux
I have created a simple hello.c which contains just the definition of an array:
unsigned char arr[4] = {1,2,3,77};
I have then compiled it with gcc -r in order to produce a relocatable object file. ...
3
votes
2
answers
150
views
GCC pragma: error: expected expression before ‘#pragma’
Please consider the following minimal example:
#include <stdio.h>
// Compile with:
// gcc -g -o myprogram main.c
//#define SPECIAL
typedef struct {
int id;
char name[50];
float value;
} ...
3
votes
0
answers
180
views
What is causing multi single-Byte access to packed Bit-field on GCC as opposed to single double word access on Clang?
While investigating some spurious tests in a x86-64Bit Yocto-based Linux system, that there were multi Byte writes to a register of a PCIe card, instead of an expected single double word write.
A ...
2
votes
1
answer
226
views
How do I resolve this warning about implicit declaration of mempcpy() after switch to Win11 WSL
Today I switched to Win11 and can no longer compile a program i was working on with gcc in wsl without "implicit declaration of function ‘mempcpy’" warnings. Before switching to Win 11 (from ...
5
votes
1
answer
239
views
GCC -O3: Why does a 32-bit write to a uint64_t appear to be ignored?
I expected this to print 11112222deadbeef (it does at -O0), but at -O3 it prints 1111222233334444.
https://godbolt.org/z/MfeEM8fqP
#include <stdint.h>
#include <stdio.h>
__attribute__((...
2
votes
1
answer
166
views
Compiling a C++ shared/dynamic library such that it cannot access any functions or variables from the main program
I'm developing a video game in C++ and Vulkan with modding support, I would really like the modding to be done through C++ (the game is optimized quite well, so I would really like the modding to be ...
0
votes
1
answer
114
views
How to install GCC-Toolset 15 in Oracle Linux 8?
According to OL-PRODUCT-LIFECYCLE.pdf , Table 2-6, GCC-Toolset 15 is available in application stream of Oracle Linux 8.10 .
However, dnf install gcc-toolset-15 fails.
It can be reproduced in a docker ...
2
votes
2
answers
215
views
Why GDB is unable to break on main()?
I am launching my a.out application manually by passing it as an argument to dynamic loader like below. My application is compiled in debug mode.
*gdb --args /lib64/ld-linux-x86-64.so.2 ./a.out
I am ...
1
vote
0
answers
47
views
How can I remove the GCC version strings from executable binaries
on .elf formats, there is a .comment section that includes compiler & linker names and versions, this is fine since its discardable via editing the linker scripts
However on Windows .exe's, while ...
0
votes
1
answer
92
views
How to make nuitka generate the same binary on GitHub Actions as locally?
I was trying to compile my python program to the smallest executable and I was pleased with this
nuitka --python-flag=-OO --onefile updater.py
As it produced this on my machine
-rwxrwxrwx 1 filip ...
2
votes
2
answers
120
views
Trying to build golang package ending up with GCC compilation segfault on as --gdwarf-5
After some package upgrade on my Ubuntu 24.04 I stumbled upon inability to build/install/work with almost any of golang packages.
So, I'm trying to install staticcheck and get the following error:
$ ...
0
votes
0
answers
34
views
avr-gcc: error: -fuse-linker-plugin is not supported in this configuration
I'm cross-compiling avr-gcc statically (in order not to depend on Android linker) to work on aarch64 android devices.
gcc is compiled with the flags:
generic_arm64:/data/data/myapp/files/sdk/hardware/...
1
vote
1
answer
64
views
What are the differences between a x86 VxWorks and a Linux object files
There are two ways to create VxWorks applications:
Real-time processes (RTP), which are akin to a process in the Unix world.
Downloadable kernel modules (DKM), which run in kernel mode, akin to a ...
4
votes
1
answer
94
views
missing-field-initializers warning for 3rd party dependency base class
I am getting a warning (turned into an error with -Werror) about missing-field-initializers when using designated initializers for the fields in my struct, because I'm not initializing fields in a 3rd ...
0
votes
0
answers
72
views
Executable killed by the system on Android, but executable via "adb shell"
I have cross-compiled GCC to run on Android arm64 device and i can run it on emulator with "adb shell":
130|generic_arm64:/data/data/com.mycompany.myproject/files/sdk/hardware/tools/avr/bin #...
3
votes
0
answers
111
views
Strange gaps in ARM GCC linker sections
TLDR: On an embedded system, I have to place certain buffers to their own section to be used with DMA. However, the resulting section seems to contain unexplainable gaps. What could be going wrong?
...
2
votes
3
answers
187
views
Bitwise operations act outside of type width in C; Compiler Bug or Within Spec?
The following derives from this question but is distinct
Consider the following code sample;
uint32_t *value = malloc(sizeof(uint32_t));
*value = 0xAAAABBBB;
int16_t *subset = (int16_t*) (value);
...
3
votes
1
answer
133
views
Adding -fsanitize=undefined in GCC makes reflect-cpp header not compile anymore [closed]
I have included the reflect-cpp header into a source file. It compiles. However if I add:
-fsanitize=undefined
It no longer compiles and complains that:
/app/raw.githubusercontent.com/boost-ext/...
1
vote
1
answer
72
views
Assembly for little-endian xtensa?
I'm trying to assemble some basic testing code for an embedded device I'm reverse-engineering, which runs little-endian xtensa threadx.
From googling the only assembler that seems to support xtensa in ...
-3
votes
1
answer
131
views
Are precompiled headers supposed to show after preprocessing? Ie., after -save-temps or -E? [closed]
I tried to make the SDL header into a precompiled header, and I noticed that when I do -save-temps or -E to ouput the precprocessed translation unit, there is no difference between just including the ...
0
votes
0
answers
43
views
How to build a gcc_tree_node from custom language Nodes
Nodes:
building a gcc_tree_node for a custom prograimming language
compile and base on C++26
the modules are avilable
the language using tab-block system
every keyword start with '/'
I want to ...
0
votes
2
answers
145
views
How do gcc optimisations work under the hood?
This problem arose while I was writing a program to retrieve file sizes. I wanted to learn more about file management and other file related things, so I wrote a c++ program using the fstream and ...