Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

unable to pass --eh-frame-hdr to linker #3965

Copy link
Copy link
@dcao

Description

@dcao
Issue body actions

When attempting to use a C++ library which exposes a C API, if the library throws an exception anywhere, even if the exception is caught in the C++ library code (i.e. it isn't thrown in the C API), the binary will terminate.

This applies both when building Zig source files that include a C header and when building C files directly via Zig (i.e. zig build-exe --c-source whatever.c).

For instance, given the following files:

// test.cpp
#include "test.h"

int etc() {
    try {
        throw 1;
    } catch (int x) {
        // No-op
    }
    return 0;
}
// test.h
#ifdef __cplusplus
extern "C" {
#endif

int etc();

#ifdef __cplusplus
}
#endif
// main.c
#include "test.h"

int main() {
    int x = etc();

    return x;
}

After building the executable, the binary terminates due to a thrown exception:

$ zig build-exe --c-source main.c --library c --object /nix/store/vgn1sxcj5ma9m5bhjps1q9jx3q2ab27c-gcc-8.3.0/lib64/libstdc++.a --object test.o --name main
$ ./main
terminate called after throwing an instance of 'int'
terminate called recursively
Aborted (core dumped)

This issue doesn't exist when building the C file with gcc or clang.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.