This is an archive of the discontinued LLVM Phabricator instance.

Do not set __guard_local to hidden for OpenBSD SSP
ClosedPublic

Authored by sisnkemp on Aug 18 2016, 9:21 AM.

Details

Summary

\_\_guard_local is defined as long on OpenBSD. If the source file contains
a definition of \_\_guard_local, it mismatches with the int8 pointer type
used in LLVM. In that case, Module::getOrInsertGlobal() returns a
cast operation instead of a GlobalVariable. Trying to set the
visibility on the cast operation leads to random segfaults (seen when
compiling the OpenBSD kernel, which also runs with stack protection).

In the kernel, the hidden attribute does not matter. For userspace code,
\_\_guard_local is defined as hidden in the startup code. If a program
re-defines \_\_guard_local, the definition from the startup code will
either win or the linker complains about multiple definitions
(depending on whether the re-defined \_\_guard_local is placed in the
common segment or not).

It also matches what gcc on OpenBSD does.

Diff Detail

Repository
rL LLVM

Event Timeline

sisnkemp updated this revision to Diff 68554.Aug 18 2016, 9:21 AM
sisnkemp retitled this revision from to Do not set __guard_local to hidden for OpenBSD SSP.
sisnkemp updated this object.
sisnkemp added a reviewer: timshen.
sisnkemp updated this object.
sisnkemp added subscribers: timshen, sisnkemp, llvm-commits.
timshen edited edge metadata.Aug 18 2016, 11:47 AM
  • Do you have a reduced testcase that produces the crash?
  • Would it be better to call M.getGlobalVariable(), assert on the returned value, and then create an IR cast on the returned GlobalValue?
  • Would it be better to call M.getGlobalVariable(), assert on the returned value, and then create an IR cast on the returned GlobalValue?

Never mind, I thought __guard_local is already declared by the time getIRStackGuard is called, but it seems not the case.

timshen accepted this revision.Aug 19 2016, 5:41 PM
timshen edited edge metadata.
This revision is now accepted and ready to land.Aug 19 2016, 5:41 PM
This revision was automatically updated to reflect the committed changes.