Skip to content

zig cc/c++: Statically linking libc++ can change program semantics #12147

Description

@topolarity

Zig Version

0.10.0-dev.3028+337147068

Steps to Reproduce

Hit this one on #11168 and realized it's a more general problem for libraries compiled with Zig.

// foo.cpp
#include <system_error>
std::error_condition foo() {
	return std::generic_category().default_error_condition(ENOENT);
}
// main.cpp
#include <system_error>
std::error_condition foo();
int main() {
	if (foo() != std::generic_category().default_error_condition(ENOENT)) {
		fprintf(stderr, "error: errors compare unequal.\n");
	}
}

With clang:

$ clang++ foo.cpp -o libfoo.so -shared
$ clang++ main.cpp -lfoo -L. -lstdc++ -rpath . -o main
$ ./main

With zig c++:

$ zig c++ foo.cpp -o libfoo.so -shared
$ zig c++ main.cpp -lfoo -L. -lstdc++ -rpath . -o main
./build/zig c++ main.cpp -lfoo -L. -lstdc++ -rpath . -o main
zig: warning: -rpath .: 'linker' input unused [-Wunused-command-line-argument]
$ ./main
error: errors compare unequal.

Expected Behavior

Library should behave the same when compiled with Zig and with Clang.

Actual Behavior

Behavior diverges because Zig links libstdc++ statically by default

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorenhancementSolving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions