[RFC] Win32 SEH Implementation

Hi all,

It seems that MSVC ABI is reaching a somehow usable state, except:

  • Byval argument passing (ongoing)
  • RTTI, which I think is not particularly difficult. 3 part of work: emit RTTI related structures, translate dynamic_cast to a library call RTDynamicCast, and translate typeid() to a library call RTTypeId
  • C++ exceptions, which is based on SEH. This is what I want to talk about here.

For C++ exceptions, we have to tackle SEH first. I understand Win32 SEH is under patent protection, but the patent will expire on April 2014. So do you think it’s time we can start working on it? If that’s the situation, here’s some initial thought about the implementation.

I looked into Win32 SEH implementation a bit. On the compiler side, the following is needed:

  • Generate a table struct for each function that utilizes SEH, containing info like __except/__finally block address, etc. Should be easy.
  • Extra instructions in prologue and epilogue. For extra epilogue instructions, we can treat them as intrinsic instead of epilogue. But for prologue it’s a different story: some instructions happen before actual prologue(alloca & register saving). My plan is add an attribute to llvm::Function.
  • To identify which __try block we are in, [ebp - 4] is used to store block id. To set it, there are “mov [bep-4], XXX” at the beginning and end of each __try block. A new llvm intrinsic for this?
  • At the beginning of __except block, esp is restored using “mov esp, [ebp - 0x18]”. A new llvm intrinsic for this?
  • If __try is paired with __finally, there will be a “call address_of_finally” in the end of the __try block. We cannot extract __finally block to a separate function, because the block may need access to local variables in the containing function. A new llvm intrinsic for this?
  • __except filter code ends with “mov eax, result; ret” (return statement of “int func(void)”), and __finally block ends with “ret” (return statement of “void func(void)”). The containing function may have different return types; are these 2 considered valid by llvm? If not, we may need intrinsic for these.

I don't know who you are, but I highly doubt you are a patent attorney
practicing in the US. As a consequence, I don't think you are really in a
good position to claim what would or would not infringe on patents, to
accurately portray them, and to give an opinion on if they are valid and
when all valid patents in any particular are might or might not expire.

Please don't discuss patents or legal issues on the mailing list. The LLVM
project mailing lists are not suitable forums for discussing such things.
If you want to discuss aspects of patents or other intellectual property
law, I would strongly encourage you to speak directly to your attorney
instead.

Please, let's all end this email discussion here. Many members of this list
are under corporate obligations to not discuss or even read rumor and
hearsay regarding patents, so having even meta discussions and debates on
the subject places all of them in the terrible position of having to pull
back from interacting with the open source community.

OK. I’m terribly sorry for saying something without knowing the potential consequences.

Chandler Carruth <chandlerc@google.com>
writes:

I don't know who you are, but I highly doubt you are a patent attorney
practicing in the US. As a consequence, I don't think you are really in a
good position to claim what would or would not infringe on patents, to
accurately portray them, and to give an opinion on if they are valid and
when all valid patents in any particular are might or might not expire.

The OPs message is 37 lines long. Only a 4 line paragraph talk about a
patent. The rest is pure technicalities.

Would you find yourself relieved if the message is reposted without that
paragraph?

Please don't discuss patents or legal issues on the mailing list. The LLVM
project mailing lists are not suitable forums for discussing such things.
If you want to discuss aspects of patents or other intellectual property
law, I would strongly encourage you to speak directly to your attorney
instead.

He is not discussing the patent. He just mentions it on passing. He
wants to discuss an implementation approach for SEH.