This is an archive of the discontinued LLVM Phabricator instance.

docs: Update SafeStack docs with separate-stack-seg feature and various USP storage modes
Needs ReviewPublic

Authored by mlemay-intel on Apr 25 2016, 8:35 AM.

Details

Reviewers
eugenis
pcc
Summary

This patch updates the SafeStack documentation to describe the
separate-stack-seg feature for helping to enable hardware segmentation on
x86-32.

It also describes the following options:

  • -safe-stack-usp-storage=single-thread
  • -safe-stack-usp-storage=tcb
  • -safe-stack-usp-tcb-offset=<offset>
  • -safe-stack-usp-init

Diff Detail

Event Timeline

mlemay-intel retitled this revision from to docs: Update SafeStack docs with separate-stack-seg feature and single-thread storage.
mlemay-intel updated this object.
mlemay-intel added a subscriber: cfe-commits.

Add documentation for -safe-stack-usp-storage=tcb, -safe-stack-usp-tcb-offset=<offset>, and -safe-stack-usp-init.

mlemay-intel retitled this revision from docs: Update SafeStack docs with separate-stack-seg feature and single-thread storage to docs: Update SafeStack docs with separate-stack-seg feature and various USP storage modes.Apr 29 2016, 8:48 PM
mlemay-intel updated this object.
pcc edited edge metadata.Apr 30 2016, 12:39 PM

We shouldn't be adding (much less documenting) -mllvm flags. Is there any reason why this behavior can't be gated on the OS?

In D19483#417844, @pcc wrote:

We shouldn't be adding (much less documenting) -mllvm flags. Is there any reason why this behavior can't be gated on the OS?

We actually already have added at least one -mllvm flag: -mllvm -safe-stack-usp-storage=single-thread. You can see an example of how it can be used here: https://github.com/contiki-os/contiki/pull/1642/commits/f13d1e22669d5526f2a721a337acd06f23a8d49d Can you please provide an example of how you think that setting should be specified without the use of the -mllvm flag?

pcc added a comment.Apr 30 2016, 2:27 PM

You should be using -target x86-unknown-contiki or similar. That should tune the behaviour to what is required for that OS. See what we have in TargetLoweringBase::getSafeStackPointerLocation to provide Android-specific behaviour for example.

The existence of flags is not justification to add more. Besides, it appears that the -safe-stack-usp-storage flag was added without proper review. It was reviewed in D15673, but the mailing list was not added as a subscriber. If I had been aware of that review I would have made the same objections at that time.

In D19483#417857, @pcc wrote:

You should be using -target x86-unknown-contiki or similar. That should tune the behaviour to what is required for that OS. See what we have in TargetLoweringBase::getSafeStackPointerLocation to provide Android-specific behaviour for example.

This makes sense for the example I gave. However, there are also more complicated situations. Sometimes it is necessary to specify different options for different files that are compiled for the same OS. For example, early during the initialization of a dynamic linker or C library, a single-threaded mode of USP storage needs to be supported. TLS is not available at that time. How should requirements like that be conveyed to the compiler?

The existence of flags is not justification to add more. Besides, it appears that the -safe-stack-usp-storage flag was added without proper review. It was reviewed in D15673, but the mailing list was not added as a subscriber. If I had been aware of that review I would have made the same objections at that time.

Sorry, I only recently learned that the mailing list should be added as a subscriber. Prior to that, I thought that patches were automatically sent to the appropriate mailing lists.

pcc added a comment.Apr 30 2016, 2:54 PM

This makes sense for the example I gave. However, there are also more complicated situations. Sometimes it is necessary to specify different options for different files that are compiled for the same OS. For example, early during the initialization of a dynamic linker or C library, a single-threaded mode of USP storage needs to be supported. TLS is not available at that time. How should requirements like that be conveyed to the compiler?

In cases like this, we should introduce a new -m flag in the Clang driver and plumb that through to the SafeStack pass using a target-specific function attribute.

In D19483#417865, @pcc wrote:

This makes sense for the example I gave. However, there are also more complicated situations. Sometimes it is necessary to specify different options for different files that are compiled for the same OS. For example, early during the initialization of a dynamic linker or C library, a single-threaded mode of USP storage needs to be supported. TLS is not available at that time. How should requirements like that be conveyed to the compiler?

In cases like this, we should introduce a new -m flag in the Clang driver and plumb that through to the SafeStack pass using a target-specific function attribute.

It appears that Clang already supports an -mthread_model=single option, so do you recommend that I remove the -mllvm -safe-stack-usp-storage=single-thread option and rely on -mthread_model instead? I added @eugenis to get his feedback as well, since he approved my patch that added the new flag. -mllvm -safe-stack-usp-storage=single-thread would have been documented for the first time by this patch, and I have not heard of anyone else using it yet.

I don't see any existing option that seems suitable for indicating that a file may be used during dynamic linker or C library initialization, so perhaps we should add an -mruntime-init flag? I welcome other naming suggestions.

pcc added a comment.Apr 30 2016, 4:02 PM

It appears that Clang already supports an -mthread_model=single option, so do you recommend that I remove the -mllvm -safe-stack-usp-storage=single-thread option and rely on -mthread_model instead?

Makes sense to me. We're free to break -mllvm flags, they are for development/debugging purposes only.

Of course, the global variable USP requires runtime support (which I assume Contiki provides), so we can probably gate this on OS + thread model.

I don't see any existing option that seems suitable for indicating that a file may be used during dynamic linker or C library initialization, so perhaps we should add an -mruntime-init flag?

Yes, I'm not sure about the name but we should do something like this.

mkuper resigned from this revision.Jun 6 2016, 4:47 PM
mkuper removed a reviewer: mkuper.