/r/gcc

Photograph via snooOG

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.

Related Subreddits

/r/gcc

2,324 Subscribers

1

Possible obscure bug, not sure

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:

8 Comments
2024/10/30
09:56 UTC

7

Porting GCC to custom architecture

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

3 Comments
2024/10/09
11:39 UTC

3

Is there an extension that declares to GCC this typedef is an error type and should always be handled?

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.

2 Comments
2024/09/24
08:20 UTC

5

How would you set cache size compilation flags for CPUs which don't have homogeneous cache sizes for their cores?

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?

1 Comment
2024/09/13
09:04 UTC

1

GCC 5.2.0 for mips exposes many symbols

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?

0 Comments
2024/09/12
18:15 UTC

1

What does this look like to experienced people - gcc errors

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

```

3 Comments
2024/09/03
15:21 UTC

5

Can I tell GCC to put a functions and everything it calls into a specific section?

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?

13 Comments
2024/08/20
00:09 UTC

1

-falign-functions=64:32:16:8

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

2 Comments
2024/08/09
19:34 UTC

11

r/GCC refers to the entire GNU compiler suite, not specifically the binary named 'gcc' that compiles C.

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.

0 Comments
2024/08/02
18:30 UTC

2

Is collect2 only needed for c++ code

... or, at least unnecessary for linking just C code (.o-s and libraries)

1 Comment
2024/07/18
18:15 UTC

2

Objdump - how to display source code for the library functions in the assembly output

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?

1 Comment
2024/07/13
21:55 UTC

1

Why doesn’t gcc have an option to build in one command but retain the object files?

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?

3 Comments
2024/07/12
05:30 UTC

4

Support for Half Precision Data Types (FP16 and BFloat16) in C, C++, and CUDA

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++:

    • Do C and C++ natively support the half-precision (FP16 and BFloat16) data types? If so, from which version of the standards are these supported?
    • If there is no native support, are there any specific extensions or libraries for handling these data types?
  • Compiler and Library Support:

    • Does compiler provide any built-in support for half-precision data types? If so, could you provide some examples or documentation references?
    • Are there any compiler flags or settings needed to enable FP16 or BFloat16 support?
  • CUDA Support:

    • How does CUDA handle half-precision data types?
  • Intel and AMD product Support:

    • How do the software stacks of Intel and AMD handle half-precision data types? I've observed that Intel products support conversion and storage of these types, but I'm uncertain about their capability for arithmetic computing. Both companies also have GPUs, yet it remains unclear how they manage reduced precision in these contexts.
  • Normalized and Subnormal Numbers:

    • I am not sure if normalized numbers and subnormal numbers refer to the same concept, but how is the support for these kinds of numbers in half-precision (FP16 and BFloat16)? Are there any particular considerations or limitations I should be aware of?

I appreciate any insights or resources you can provide on this topic. Thank you in advance for your help!

11 Comments
2024/07/04
08:03 UTC

0

Anyone know what happened to u/rhy0lite?

For a very long time, /u/rhy0lite has posted each GCC release here, but has gone MIA for some months now.

0 Comments
2024/07/03
18:02 UTC

5

Help

https://preview.redd.it/o1zyklfcf6ad1.png?width=1919&format=png&auto=webp&s=4e59a5bcc5c51d087ba70a2836bfb91ffcc8b5aa

I've tried re installing the MinGW setup, repeated all the steps for setting up vscode given in the website, still no change.

5 Comments
2024/07/02
21:52 UTC

1

GCC Help

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 🙏🙏

https://preview.redd.it/9ys8upbiqj8d1.png?width=3832&format=png&auto=webp&s=2326a4012ae703bd2b5ea5901c052a8f94a97bce

5 Comments
2024/06/24
16:28 UTC

0

GNU CC refusing to recognize ANY external header files. HELP!

So i'm planning to make a cpp app in gtk. However, EVERYTIME i put ANY header file into this path:

https://preview.redd.it/nq252pqfpj7d1.png?width=1920&format=png&auto=webp&s=7b6363b6f8ea92f544c0c360350fb85928ffdf9e

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:

https://preview.redd.it/f5xt5w4opj7d1.png?width=1920&format=png&auto=webp&s=051099a5a113a0162e54a904cef62690a754dca5

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.

3 Comments
2024/06/19
15:20 UTC

2

GCC Plugin - Defining Named Labels as Symbols

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 use
readelf -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!

1 Comment
2024/06/19
08:22 UTC

0

Help with disassembling a C executable file

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

https://preview.redd.it/bla25ybsis6d1.png?width=1117&format=png&auto=webp&s=ed79fcff1b7c238992e30a33c5fc45b808a26613

3 Comments
2024/06/15
19:53 UTC

0

Is it possible to somehow have executable itself determine shared library load path for Linux ?

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.

2 Comments
2024/06/08
20:15 UTC

1

How does gcc handle naming conflicts in libraries?

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?

3 Comments
2024/06/01
02:21 UTC

2

GCC Plugin - Keeping State

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

1 Comment
2024/05/29
12:58 UTC

1

Not optimal GCC13 output for simple function in RISC-V

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.

1 Comment
2024/05/21
12:38 UTC

1

Is there an attribute for no overflow/underflow?

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)

2 Comments
2024/05/21
06:53 UTC

1

pragma message in assembly (*.S)

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?

0 Comments
2024/05/15
08:15 UTC

7

GCC 14 was released yesterday and it's a pretty full release for Arm. Check out of 3 part blog series on what Arm engineeers have been up to https://community.arm.com/arm-community-blogs/b/tools-software-ides-blog/posts/p1-gcc-14

1 Comment
2024/05/08
08:24 UTC

1

I want c++20 and <bits/stdc++.h> both

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.

6 Comments
2024/05/02
11:45 UTC

2

Is there a way to detect what encoding GCC is compiling the file as?

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?

8 Comments
2024/04/24
04:38 UTC

Back To Top