Skip to content

Conversation

@mcourteaux
Copy link
Contributor

@mcourteaux mcourteaux commented May 14, 2025

I don't know if the namespace issue is a GCC bug, or actually correct language behavior, but the declarations that look like this:

namespace Halide {

namespace { // < anonymous!!
extern "C" int something;
}

namespace Internal { // < named
extern "C" int other;
}

}

Yield these symbols:

0000000000000000         *UND*	0000000000000000        Halide::(anonymous namespace)::something
0000000001025ae0 g     O .data	0000000000000ca5        other

So this behavior is different for GCC when dealing with anonymous namespaces and when dealing with named namespaces. The named namespaces lift extern "C" declarations out to global scope, whereas the anonymous have them still in the namespace.

To be honest, I'm clueless if this extern "C" inside a namespace makes any sense at all. Doesn't sound very C.

…ually the global :: namespace, instead of having them sit inside the Halide::(anonymous) namespace. Fixes issue on G++ 15.
@mcourteaux mcourteaux changed the title Fix build on Fedora 42. Fix build on GCC 15 (Comes with Fedora 42). May 14, 2025
@abadams
Copy link
Member

abadams commented May 14, 2025

extern "C" disables name mangling for a symbol and gives it extern linkage, so it shouldn't matter if it's in a namespace or not. However an anonymous namespace gives everything inside inline linkage. It's not clear to me from the C++ standard if the "extern" is supposed to take precedence or not. I guess it's better to just avoid it. The change to StmtToHtml.cpp shouldn't be technically necessary, but it's clearer out of the namespace.

@abadams abadams merged commit b7991c1 into halide:main May 14, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants