post-link Dwarf information appears wrong, works in JIT

I'm working on exception handling and having some trouble with type
information. My personality/types work fine when running in the JIT, but
when I produce object files and link them it fails.

In particular, from an action record and the LSDA I get a type table
entry. The problem is this doesn't appear to be pointing to a valid
location. If I derefence it a segfault occurs.

Are there perhaps some linker flags that I must use to get this working
correctly?

There shouldn't be any special linker flags you need to use. If you're getting segfaults, it's probably trying to access the data at an invalid location or something. Make sure that your EH table is properly aligned. You might want to hand calculate the values to make sure that they're correct. What platform are you using?

-bw

I don't know that I do anything to alter the alignment: I'm just using
the "addClause" function of the landingpad. Platform is x86_64 on Linux.
Note that in the JIT my code does work, so my assumption is that I
haven't done something completely wrong, just partially wrong.

I'm looking at code generated by clang from C++, and I notice a few
differences. Are these relevant?
- the clauses are always cast to i8* (I'm using an i64* as that is my
type information)
- the global variable is marked linkonce_odr unnamed_addr

There shouldn't be any special linker flags you need to use. If
you're getting segfaults, it's probably trying to access the data at
an invalid location or something. Make sure that your EH table is
properly aligned. You might want to hand calculate the values to make
sure that they're correct. What platform are you using?

I don't know that I do anything to alter the alignment: I'm just using
the "addClause" function of the landingpad. Platform is x86_64 on Linux.
Note that in the JIT my code does work, so my assumption is that I
haven't done something completely wrong, just partially wrong.

I'm looking at code generated by clang from C++, and I notice a few
differences. Are these relevant?
- the clauses are always cast to i8* (I'm using an i64* as that is my
type information)

I forget, but it may be relevant. Try changing it and see if it helps.

- the global variable is marked linkonce_odr unnamed_addr

I don't think that that would affect anything. What's the ASM look like between the JIT and the .s file?

-bw

- the clauses are always cast to i8* (I'm using an i64* as that is my
type information)

I forget, but it may be relevant. Try changing it and see if it helps.

I've tried this and it doesn't help. I also tried using a different type
(a structure type) for the types and it doesn't help.

- the global variable is marked linkonce_odr unnamed_addr

I don't think that that would affect anything. What's the ASM look like between the JIT and the .s file?

I'm not clear on what you wish me to compare. I have attached a small IR
program that shows how I am adding the clauses. I then just link with:

gcc -Wl,--eh-frame-hdr,--build-id -o exe object_a.o object_b.o object_c.o

except.ll (2.05 KB)

I added several more clauses to see the result. It looks like the
landing pad information is generated correctly: I get the correct number
of action records, each record has a reasonable index into the type
table (from 1 to 9). The encoded address increment in 4 however, which
is unexpected since they are size 8 (in the JIT they increment by 8).
Whatever is causing that may also be responsible for the type table
address being incorrect.

It's the same IR code, so I presume there's something wrong with the
linking via gcc.

I'm dubious that it's a linking problem. These are in their own section and should be aligned correctly. You might be reduced to stepping through the unwinding library with your debugger (I have battle stories about doing that). You can find out what the personality function is really reading and if it's unaligned or just garbage data or something...

-bw

This is what I'm doing. I wrote the personality routine (using third
party dwarf decoding). The results of my stepping/debugging differ based
on whether the program is run in the JIT or compiled to an EXE. This is
what leads me to believe something in the link process is not going as I
would like.

I got frustrated and started changing random linker settings. When I
changed PIC_ to Default for the Reloc model it started working. I don't
understand why yet, but it seems like a good idea to keep investigating
the link aspect.