[Issue 23061] New: Exceptions cannot be caught by catch statement in static build

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 26 11:39:55 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23061

          Issue ID: 23061
           Summary: Exceptions cannot be caught by catch statement in
                    static build
           Product: D
           Version: D2
          Hardware: x86
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: ttanjo at gmail.com

Exceptions cannot be caught in the static linked configuration but they should
be caught.
In the dynamic linked configuration, they can be caught as intended.

I first filed it in ldc but finally I found it is a issue in druntime.
- https://github.com/ldc-developers/ldc/issues/3965

# Reproduced versions
I checked this issue with the following environment with Docker container.
- dmd 2.098.0-r0 in Alpine Linux 3.15
- ldc 1.28.0-r0 in Alpine Linux 3.15
- ldc 1.28.1-r0 in Alpine Linux edge

# How to reproduce

app.d:

```dlang
void main(string[] args)
{
        try
        {
                throw new Exception("aaa");
        }
        catch(Exception e)
        {
        }
}
```

Compile and execute it in Alpine Linux image as follows:

```console
$ docker run --rm -it -v $PWD:/workdir -w /workdir alpine:3.15 sh
# apk --no-cache add dmd gcc musl-dev llvm-libunwind-static
# dmd -c app.d
# gcc -static app.o -o app -lphobos2 -lunwind
# ldd app
/lib/ld-musl-x86_64.so.1: app: Not a valid dynamic program
# ./app
```

# Expected behavior
It can be executed without errors.

# Actual behavior
It fails execution with the exception message.

```console
# ./app
src/rt/dwarfeh.d:330: uncaught exception reached top of stack
This might happen if you're missing a top level catch in your fiber or signal
handler
object.Exception at app.d(11): aaa
----------------
??:? <ERROR: Unable to retrieve function name> [0x0]
Aborted
```

Note that it can successfully be executed when I compile it with `dmd app.d`.

---
I reproduce the same issue with ldc as the following instructions:

```console
$ docker run --rm -it -v $PWD:/workdir -w /workdir alpine:3.15 sh
# apk --no-cache add ldc gcc musl-dev llvm-libunwind-static
# ldc2 -static app.d
# ./app
rt/dwarfeh.d:354: uncaught exception reached top of stack
This might happen if you're missing a top level catch in your fiber or signal
handler
object.Exception at app.d(11): aaa
----------------
src/ctype/isspace.c:10 <ERROR: Unable to retrieve function name> [0x0]
Aborted
```

--


More information about the Digitalmars-d-bugs mailing list