LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1414 - Should support multiple personality functions per module
Summary: Should support multiple personality functions per module
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Common Code Generator Code (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks: 870
  Show dependency tree
 
Reported: 2007-05-12 15:49 PDT by Anton Korobeynikov
Modified: 2015-01-14 16:28 PST (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Korobeynikov 2007-05-12 15:49:32 PDT
Current LLVM's EH design in some cases is neither consistent nor complete: in
one places it assumes only 1 personality function per module (and thus only one
common EH frame), but in other places it can theoretically support multiple
personality functions (recording them in the landing pads), but ... lacks callee
traversal code in order to assign them correct personality function.

For now I'm going to do "only one personality function per module". This will
allow to emit eh information at least without extra "hacks" and workaround.

Later (maybe for 2.1) we will probably do extra cfg traversal code in order to
assign correct personality function. However, this seems to be many problems
with indirect function calls....
Comment 1 Anton Korobeynikov 2007-05-13 10:44:25 PDT
Partly implemented in:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070507/049541.html
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070507/049542.html

Now we're restricted only to one personality function per eh frame (=per
function). This is much better. Also, these patches allows us not to do CFG
traversal (whoo!).
Comment 2 Duncan Sands 2007-05-14 05:49:37 PDT
A possible trick is to define our own personality function: this
would do some extra reasoning to identify the correct real
personality function, then dispatch to that one.  For example it
could just call each real personality function in turn until it
finds one that handles the exception.  It could also do something
more clever based on the ip.
Comment 3 Chris Lattner 2007-05-14 12:31:17 PDT
I don't think that will work, it breaks binary/ABI compatibility with GCC.
Comment 4 Duncan Sands 2007-05-14 13:40:04 PDT
> I don't think that will work, it breaks binary/ABI compatibility with GCC.

Why?
Comment 5 Chris Lattner 2007-05-14 19:20:28 PDT
Because llvm-compiled C++/Ada files would produce references to symbols that don't exist in gcc 
compiled libstdc++.
Comment 6 Duncan Sands 2007-05-14 21:10:18 PDT
> Because llvm-compiled C++/Ada files would produce references to symbols that 
> don't exist in gcc compiled libstdc++.

The fake personality functions would be generated in each .s that
needs them.
Comment 7 Chris Lattner 2007-05-14 23:17:44 PDT
ok, that leads to code bloat :)
Comment 8 Duncan Sands 2007-05-15 04:38:34 PDT
> ok, that leads to code bloat :)

Yes, but since there would be most likely only one of
these per module that's not so bad.  Also, even if there
was one per function, that's still not so bad compared to
the size of the eh tables themselves.  All this fake personality
function has to do is: call real_personality_1; return if result=found;
call real_personality_2; return if result=found; That's not a huge
amount of code.  The minimum size of a eh table seems to be 16 bytes.

Anyway, hopefully this kind of trick won't be needed at all.  It's
a last resort if we can't get the desired effect more directly.
Comment 9 Duncan Sands 2007-05-15 07:39:46 PDT
Also, by playing linkage tricks (eg: weak linkage) it may be possible
to get down to one copy per executable, even if we output one copy per
.s.
Comment 10 Chris Lattner 2007-05-15 12:59:29 PDT
I don't get it.  What problem are you trying to solve?
Comment 11 Chris Lattner 2007-05-15 13:02:55 PDT
To be more specific: dwarf EH tables support multiple personality functions per executable, so we just 
need to emit the right tables if there are multiple personality functions in a module. 
Comment 12 Duncan Sands 2007-05-15 13:07:04 PDT
> dwarf EH tables support multiple personality functions per executable

Multiple personalities *per function*.  I don't know if this is
supported, so just threw out this fake personality idea in case
it isn't supported.  It seems to have grown a life of its own :)
Comment 13 Chris Lattner 2007-05-15 13:08:45 PDT
<disclaimer>I have no idea what I'm talking about</>

That said, it seems like it's just a matter of having the range table have entries for different personalities.  
There are two issues: 1) book keeping at the llvm level, so you know the personality of each call, and 2) 
emitting the tables correctly in the code generator.
Comment 14 Reid Kleckner 2015-01-14 16:28:19 PST
So far as I can tell, LLVM does in fact support multiple personalities per module, so I'll mark it fixed as per the title.

The rest of the bug comments discuss multiple personalities in one function. Supporting multiple personalities in a single function is IMO infeasible, as we'd need to split the function in the backend so that different regions of code have different EH tables. We'd also need some crazy CFI to make it work. Each object file format would present a unique set of challenges as well.