/r/gcc
Created by the GNU project GCC is a compiler system for C, C++, Objective-C, Fortran, Java, Ada, and Go.
Created by the GNU project GCC is a compiler system for C, C++, Objective-C, Fortran, Java, Ada, and Go.
/r/gcc
Hey!
I'm writing some C code using a Raspberry Pi v5 (long story, don't ask), and pushing the code to GitHub, which runs a series of tests.
My issue is with the format checking, specifically checking of types. The CFLAGS specifies -Wformat=2
in each makefile, and the GitHub actions do catch errors like this:
printf("%d", sizeof(int)); //wrong type
However, for some reason the GCC on my rpi doesn't report any issues here at all. Why are these two platforms inconsistent? IDK what to do or even how to report this as a bug.
Thanks in advance.
Contexts:
Does anyone know a good tutorial or something about how to port GCC to a custom processor architecture? I am working on a VM as a school project, and I have made my own assembly-like language for it. It is a 32bit processor if that helps
Let's say I have this:
enum
{
foo_err_nomem = ENOMEM,
...
} foo_err_t;
foo_err_t foo(...);
Is there a way to make gcc throw compile time errors if all the outputs of foo() is not handled? The only thing I can think of is this:
enum
{
foo_err_nomem = ENOMEM,
...
} foo_err_t;
foo_err_t _foo(...);
#define foo(...) switch ( _foo(...) )
Not ideal since dev could just use _foo() directly but it's the only solution I can think of. Is there some better way that gcc, clang, etc would support? I'm mainly after gcc or maybe winegcc depending on how things go with my project. I'm locking my custom library and whatnot into GNU binaries to avoid ABI issues so using extensions in the library interface is a non-issue.
I'm trying to figure out how to best use cache size flags (--param=l1-cache-size=... --param=l2-cache-size=...) for modern intel processors (with E cores) and for some modern AMD processors (7950X3D) which do not have the same amount of L1 or L3 cache for all cores.
^(note: --param=l2-cache-size doesn't actually refer to L2, it refers to the cache "closest to RAM", so L3 for most if not all modern processors.)
For intel, E cores have lower amount of L1 cache than P cores, and for AMD, the 7950X3D has two 8 core-complexes where one has much more L3 cache than the other.
The way I see it, there are three ways of handling this:
a) Set the parameter to the greater of the two cache sizes
b) Set the parameter to the lesser of the two cache sizes
c) Leave the parameter unset so that gcc won't assume anything about the non-homogeneous cache size, only set the other homogeneous one (L3 for intel, L1 for AMD)
I think a) would be the worst because it might cause gcc to misoptimize thinking it has more cache than it actually does for some cores, which could cause unnecessary cache misses. I'm not so sure about b) and c) though. What do you think?
I created a gcc toolchain for mips-uclibc 32bit be and when I compile any executable many internal symbols end up in the dynamic symbol table. -fvisibillity=hidden did not solve this, using LTO left lto private symbols exposed. Any idea why this is happening and how to fix this?
The code I am compiling compiles on other systems but I am trying to make it build in nix.
I am getting invalid syntax errors, and a lot of stuff like
`_ISspace’ was not declared in this scope; did you mean ‘isspace`
where stuff is seemingly just slightly renamed.
Does this point towards a wrong version of gcc, wrong version of included libraries. Could anyone please point me in the right direction I've been hitting my head against the wall in total for 3 weeks in getting all this working
```
/nix/store/px65na1fysh9wb9mj30lgpf6c3njx7zv-gcc-13.3.0/include/c++/13.3.0/streambuf:135:57: error: no type named ‘int_type’ in ‘std::basic_streambuf<wchar_t>::traits_type’ {aka ‘struct std::char_traits<wchar_t>’}
135 | typedef typename traits_type::int_type int_type;
| ^~~~~~~~
In file included from /nix/store/px65na1fysh9wb9mj30lgpf6c3njx7zv-gcc-13.3.0/include/c++/13.3.0/bits/locale_facets.h:39,
from /nix/store/px65na1fysh9wb9mj30lgpf6c3njx7zv-gcc-13.3.0/include/c++/13.3.0/bits/basic_ios.h:37,
from /nix/store/px65na1fysh9wb9mj30lgpf6c3njx7zv-gcc-13.3.0/include/c++/13.3.0/ios:46:
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/tr1/cwctype: At global scope:
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/tr1/cwctype:47:14: error: ‘iswblank’ has not been declared in ‘std’
47 | using std::iswblank;
| ^~~~~~~~
In file included from /nix/store/px65na1fysh9wb9mj30lgpf6c3njx7zv-gcc-13.3.0/include/c++/13.3.0/bits/locale_facets.h:41:
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:49:35: error: ‘_ISupper’ was not declared in this scope; did you mean ‘isupper’?
49 | static const mask upper = _ISupper;
| ^~~~~~~~
| isupper
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:50:35: error: ‘_ISlower’ was not declared in this scope; did you mean ‘islower’?
50 | static const mask lower = _ISlower;
| ^~~~~~~~
| islower
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:51:35: error: ‘_ISalpha’ was not declared in this scope; did you mean ‘isalpha’?
51 | static const mask alpha = _ISalpha;
| ^~~~~~~~
| isalpha
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:52:35: error: ‘_ISdigit’ was not declared in this scope; did you mean ‘isdigit’?
52 | static const mask digit = _ISdigit;
| ^~~~~~~~
| isdigit
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:53:35: error: ‘_ISxdigit’ was not declared in this scope; did you mean ‘isxdigit’?
53 | static const mask xdigit = _ISxdigit;
| ^~~~~~~~~
| isxdigit
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:54:35: error: ‘_ISspace’ was not declared in this scope; did you mean ‘isspace’?
54 | static const mask space = _ISspace;
| ^~~~~~~~
| isspace
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:55:35: error: ‘_ISprint’ was not declared in this scope; did you mean ‘isprint’?
55 | static const mask print = _ISprint;
| ^~~~~~~~
| isprint
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:56:35: error: ‘_ISalpha’ was not declared in this scope; did you mean ‘isalpha’?
56 | static const mask graph = _ISalpha | _ISdigit | _ISpunct;
| ^~~~~~~~
| isalpha
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:56:46: error: ‘_ISdigit’ was not declared in this scope; did you mean ‘isdigit’?
56 | static const mask graph = _ISalpha | _ISdigit | _ISpunct;
| ^~~~~~~~
| isdigit
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:56:57: error: ‘_ISpunct’ was not declared in this scope; did you mean ‘ispunct’?
56 | static const mask graph = _ISalpha | _ISdigit | _ISpunct;
| ^~~~~~~~
| ispunct
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:57:35: error: ‘_IScntrl’ was not declared in this scope; did you mean ‘iscntrl’?
57 | static const mask cntrl = _IScntrl;
| ^~~~~~~~
| iscntrl
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:58:35: error: ‘_ISpunct’ was not declared in this scope; did you mean ‘ispunct’?
58 | static const mask punct = _ISpunct;
| ^~~~~~~~
| ispunct
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:59:35: error: ‘_ISalpha’ was not declared in this scope; did you mean ‘isalpha’?
59 | static const mask alnum = _ISalpha | _ISdigit;
| ^~~~~~~~
| isalpha
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:59:46: error: ‘_ISdigit’ was not declared in this scope; did you mean ‘isdigit’?
59 | static const mask alnum = _ISalpha | _ISdigit;
| ^~~~~~~~
| isdigit
/nix/store/skkw2fidr9h2ikq8gzgfm6rysj1mal0r-gcc-13.2.0/include/c++/13.2.0/x86_64-unknown-linux-gnu/bits/ctype_base.h:61:35: error: ‘_ISblank’ was not declared in this scope; did you mean ‘isblank’?
61 | static const mask blank = _ISblank;
| ^~~~~~~~
| isblank
```
I have an interrupt service routine, which I want to put in a specific, non-standard, section, to be put in a special RAM region of my microcontroller. So far so good. But. Every function called from that interrupt service routine should also be put in that special RAM region. I realize [[gnu::flatten]]
is an option, but I'd prefer something less drastic. Is that possible to do?
Hey guys , iam wondering if this is a correct syntax of the flag , and if its like what i understand is : align for 64 and 32 as fallback and so one and so fourth , if anyone had some depth understanding plz explain this flag
In other words, this is not a dedicated C-language subreddit. In the sidebar, do notice that r/C_programming and r/cpp_questions also exist.
... or, at least unnecessary for linking just C code (.o-s and libraries)
When I use objdump with -S flag, only the main program's source code is displayed in the assembly output. How do I display the linked libraries' source code as well? For example, if I use pthread_create() function in my program, I want the source code of this function included as well. How do I do that?
It seems the only command to save intermediate files is -save—temps, but this saves all intermediate files. Is the only way to save only .o files to use -c option and build in two commands?
Hi everyone,
I am currently exploring the use of half-precision data types, specifically FP16 and BFloat16, for storage, conversion and arithmetic computation. I have a few questions regarding their support in C, C++, and CUDA.
Native Support in C and C++:
Compiler and Library Support:
CUDA Support:
Intel and AMD product Support:
Normalized and Subnormal Numbers:
I appreciate any insights or resources you can provide on this topic. Thank you in advance for your help!
For a very long time, /u/rhy0lite has posted each GCC release here, but has gone MIA for some months now.
I've tried re installing the MinGW setup, repeated all the steps for setting up vscode given in the website, still no change.
Hey guys, im just starting out self studying C. Im using VSC as my IDE for the first time. im currently experiencing this error when i try to compile files using GCC on the terminal. Picture attached. Im using a M2 Pro macbook pro. Anyone have any idea what im doing wrong?
Thanks in advance 🙏🙏
So i'm planning to make a cpp app in gtk. However, EVERYTIME i put ANY header file into this path:
and include it in my file in vs code, it either says cannot open source file dependency gtk/css/gtkcss.h .
Not just gtk, anything! Gcc fails to recognize any header file except for like stdio, string, stdlib etc. Which is very painful. Can someone please help me? This is what happens:
I'm extremely disappointed on how hard this is. I'm using msys64. WHY?!?!?! WHY GNU WHY!!!! YOU'VE BEEN EATING MY HEAD FOR A WEEK! and no this is NOT a ms cpp tool include path error. See the terminal for reference.
Hey, fairly new to writing gcc plugins
I am using a GIMPLE pass to instrument basic_blocks.
For some un-interesting reasons, I want to mark each instrumentation location so later on I can find their addresses.
For that, I wanted each basic block to be instrumented as so:
if (..)
{
instrument_fn();
lbl_51818as8d2:
... original code ...
}
I am successfully adding the function call but the label is not found when I usereadelf -s | grep lbl
I tried using
build_decl(UNKNOWN_LOCATION, LABEL_DECL, get_identifier("lbl_51818as8d2"), void_type_node)
gimple_build_label()
and then
gsi_insert_before
Any ideas? Or a better way to make GCC create a symbol that points to a location?
Thanks!
I accidentally used "gcc -o 17.c -lm" and it deleted my 17.c file, i still have a compiled file of that file, how can i convert that compiled file to C code? Im new at linux and gcc
I was just wondering is say you have executable and you do not want to change ld library path before running it and also the executable not linked using rpath, then can executable itself somehow determine directories to search for shared lib ?
The reason I ask is say I don’t want to have to have a user change their environment before they run executable but would rather have executable pick path based on some external configuration file.
I thought maybe some magic could be done with gcc constructor attribute functions.
I've been building an application with ncurses and it's sister library menus. Obviously, I'm compiling it with -lmenus
. This made me think though, there's no way that's the only popular library out there named menus. I installed it along with ncurses using apt, with no consideration of where I was installing it. So what happens if I install another library named/compiled with menu using apt?
Hey, I am very new to writing GCC Plugins.
I have used the code from here and extended it so I can instrument each basic_block with my own function call, for coverage testing (long story short - i cannot use gcov)
Now, each basic block passes an assigned index to a profiling function.
The issue is, the branch counter is reset for each `obj` file compiled, so each branch count starts from 0 for each compiled obj..
Is there a (good) way to keep state between executions?
Thank you
Hi all,
I need to optimize my rom code to a minimum in my project and I compile my code with GCC13 with the -Os option for minimum code size.
But I still see some very not optimal output code which could be easily optimized by the compiler.
For example, I have the following function to load 2 variables from RAM, multiply them and store the result back to RAM:
#define RAMSTART 0x20000000
void multest(void) {
int a, b, c;
a = *((int*)(RAMSTART + 0));
b = *((int*)(RAMSTART + 4));
c = a * b;
*((int*)(RAMSTART + 8)) = c;
}
The output of GCC13 with -Os is like this:
00000644 <multest>:
644:
200006b7
lui
x13,0x20000
648:
00468693
addi
x13,x13,4 # 20000004
64c:
20000737
lui
x14,0x20000
650:
00072703
lw
x14,0(x14) # 20000000
654:
0006a683
lw
x13,0(x13)
658:
200007b7
lui
x15,0x20000
65c:
02d70733
mul
x14,x14,x13
660:
00e7a423
sw
x14,8(x15) # 20000008
664:
00008067
jalr
x0,0(x1)
The whole output looks like a mess, since it loads the same RAM address (0x20000) too many times when it could have just loaded it once in a register it does not use in the multiplication and use the immediate offset in the LW and SW instructions like it does at addr 660. Also that ADDI at 648 is unnecessary.
Is this the state of GCC optimization for RISC-V at the moment ? It is really sad to waste so many opcodes for nothing.
Am I missing something here ?
EDIT1: It seems to be a problem of only GCC 13. https://godbolt.org/z/W6x7c9W5T
GCC 8, 9, 10, 11, 12, and 14 all output the expected minimal code. Very weird.
By this I mean the compiler would spit out an error every time the integer/float type is allowed to overflow/underflow without proper checking of the result. So for example I could write something like typedef __attribute__((nowrap)) long nwlong;
and then later use nwlong x = a + b; if ( x > c ) { ... }
which would trigger the error simply because there's nothing like ((a && b) ? x > a : x >= a) && ((a && b ? x > b : x >= b) &&
before x > c
to catch overflow/underflow.
Or maybe instead of an error it should always trigger an exception. I'm happy with either way. I just want to add some typedefs in my project for it next to my normal ones so as to remind the dev (or inform newbies) that there is a possibility of that happening with the normal ones.
If not can the next version of GCC include such an attribute please (in addition to the _BitInt(N)
which is essential to my project - currently using clang because every attempt to compile GCC just results in some "cannot remove gcc" error when it tries to replace the current one)
I have an assembly file (e.g., file.S) where I want to use #pragma message
to show the expansion of a macro, but it isn't showing up.
A quick test, in here when compiling C we get the output of the warning and the message, but when compiling assember with cpp (which I assume is what it's used when compiling *.S), then we only we the output of the warning.
$ echo -e "#warning my warning\n#pragma message \"my message\"" | gcc -c -x c -
<stdin>:1:2: warning: #warning my warning [-Wcpp]
<stdin>:2:9: note: ‘#pragma message: my message’
$ echo -e "#warning my warning\n#pragma message \"my message\"" | gcc -c -x assembler-with-cpp -
<stdin>:1:2: warning: #warning my warning [-Wcpp]
I skimmed over the man page and https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html, but I couldn't find how to do it.
Does anyone know if #pragma message ...
are supported in *.S files and if so, how do I enable them?
So I want to install c++ compiler which will suport c++20 and I also want to use the header file <bits/stdc++.h>.
when i installed MSYS2 i did not get bits headerfile.
when i installed mingw from sourceforge it gave me gcc 6.x which doesnt support c++20
please help me getting both with an easy process.
I want to do something like this:
#if !defined(FILE_IS_UTF8)
# error "File MUST be in UTF-8 encoding!"
/* Make absolute certain the compiler quits at
this point by including a header that is not
supposed to exist */
# include <abort_compilation.h>
#endif
Is there a way to do so?