llvm-project/llvm/docs
Hans Wennborg 2bc57d85eb Don't override __attribute__((no_stack_protector)) by inlining (PR52886)
Since 26c6a3e736, LLVM's inliner will "upgrade" the caller's stack protector
attribute based on the callee. This lead to surprising results with Clang's
no_stack_protector attribute added in 4fbf84c173 (D46300). Consider the
following code compiled with clang -fstack-protector-strong -Os
(https://godbolt.org/z/7s3rW7a1q).

  extern void h(int* p);

  inline __attribute__((always_inline)) int g() {
    return 0;
  }

  int __attribute__((__no_stack_protector__)) f() {
    int a[1];
    h(a);
    return g();
  }

LLVM will inline g() into f(), and f() would get a stack protector, against the
users explicit wishes, potentially breaking the program e.g. if h() changes the
value of the stack cookie. That's a miscompile.

More recently, bc044a88ee (D91816) addressed this problem by preventing
inlining when the stack protector is disabled in the caller and enabled in the
callee or vice versa. However, the problem remained if the callee is marked
always_inline as in the example above. This affected users, see e.g.
http://crbug.com/1274129 and http://llvm.org/pr52886.

One way to fix this would be to prevent inlining also in the always_inline
case. Despite the name, always_inline does not guarantee inlining, so this
would be legal but potentially surprising to users.

However, I think the better fix is to not enable the stack protector in a
caller based on the callee. The motivation for the old behaviour is unclear, it
seems counter-intuitive, and causes real problems as we've seen.

This commit implements that fix, which means in the example above, g() gets
inlined into f() (also without always_inline), and f() is emitted without stack
protector. I think that matches most developers' expectations, and that's also
what GCC does.

Another effect of this change is that a no_stack_protector function can now be
inlined into a stack protected function, e.g. (https://godbolt.org/z/hafP6W856):

  extern void h(int* p);

  inline int __attribute__((__no_stack_protector__)) __attribute__((always_inline)) g() {
    return 0;
  }

  int f() {
    int a[1];
    h(a);
    return g();
  }

I think that's fine. Such code would be unusual since no_stack_protector is
normally applied to a program entry point which sets up the stack canary. And
even if such code exists, inlining doesn't change the semantics: there is still
no stack cookie setup/check around entry/exit of the g() code region, but there
may be in the surrounding context, as there was before inlining. This also
matches GCC.

See also the discussion at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94722

Differential revision: https://reviews.llvm.org/D116589
2022-01-13 12:04:49 +01:00
..
AMDGPU [AMDGPU][MC][NFC][DOC] Updated description of registers 2021-09-03 13:09:54 +03:00
AMDGPUDwarfExtensionAllowLocationDescriptionOnTheDwarfExpressionStack [AMDGPU][NFC] Update DWARF extension allowing locations on stack 2021-12-28 17:12:20 +00:00
CommandGuide [MCA] Switching from conservatively guessing which instructions are 2022-01-11 13:50:14 -08:00
DependenceGraphs [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
Frontend [llvm] Fix typos in documentation (NFC) 2021-02-27 10:09:23 -08:00
GlobalISel [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
HistoricalNotes
PDB [NFC][llvm] Inclusive language: replace master in llvm docs 2021-11-25 13:36:51 -06:00
Proposals [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
TableGen [Docs] Fix IR and TableGen grammar inconsistencies 2022-01-13 11:55:13 +01:00
_ocamldoc
_static
_templates
_themes/llvm-theme
tutorial [docs]LLVM Tutorial: fix the typo in Cpu0 URL 2021-12-20 21:45:57 +00:00
AMDGPUDwarfExtensionsForHeterogeneousDebugging.rst [AMDGPU][NFC] Update to DWARF extension for heterogeneous debugging 2021-12-28 17:13:45 +00:00
AMDGPUInstructionNotation.rst [AMDGPU][MC][NFC][DOC] Updated AMD GPU assembler syntax description. 2021-08-27 17:23:20 +03:00
AMDGPUInstructionSyntax.rst [AMDGPU][MC][NFC][DOC] Updated AMD GPU assembler syntax description. 2021-08-27 17:23:20 +03:00
AMDGPUModifierSyntax.rst [AMDGPU][MC][NFC][DOC] Updated AMD GPU assembler syntax description. 2021-08-27 17:23:20 +03:00
AMDGPUOperandSyntax.rst [AMDGPU][MC][NFC][DOC] Updated description of registers 2021-09-03 13:09:54 +03:00
AMDGPUUsage.rst [AMDGPU][NFC] Update to DWARF extension for heterogeneous debugging 2021-12-28 17:13:45 +00:00
ARM-BE-bitcastfail.png
ARM-BE-bitcastsuccess.png
ARM-BE-ld1.png
ARM-BE-ldr.png
AddingConstrainedIntrinsics.rst
AdvancedBuilds.rst Update documentation and implementation of stage3 build 2020-10-08 07:55:37 +02:00
AliasAnalysis.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
Atomics.rst [AArch64] Out-of-line atomics (-moutline-atomics) implementation. 2020-11-20 13:30:12 +00:00
Benchmarking.rst
BigEndianNEON.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
BitCodeFormat.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
BlockFrequencyTerminology.rst
BranchWeightMetadata.rst
BugLifeCycle.rst
Bugpoint.rst
BugpointRedesign.md
BuildingADistribution.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
CFIVerify.rst
CMake.rst [llvm] Use `GNUInstallDirs` to support custom installation dirs 2022-01-08 00:47:31 +00:00
CMakeLists.txt
CMakePrimer.rst
CodeGenerator.rst [docs][GISel]Added GISel documentation link 2021-06-24 00:55:00 +05:30
CodeOfConduct.rst
CodeReview.rst [docs] Set Phabricator as the tool for pre-commit reviews 2021-06-07 11:50:52 -05:00
CodingStandards.rst [doc] Fix namespace comment style in Coding Guidelines 2021-12-07 13:36:25 +00:00
CommandLine.rst Use ManagedStatic and lazy initialization of cl::opt in libSupport to make it free of global initializer 2021-07-16 07:38:16 +00:00
CompileCudaWithLLVM.rst [CUDA] Bump supported CUDA version to 11.5 2021-11-09 08:20:53 +00:00
CompilerWriterInfo.rst [VE] Add manuals to CompilerWriterInfo 2021-12-23 14:14:37 +01:00
Contributing.rst docs: update some bug tracker references (NFC) 2022-01-10 15:59:08 -08:00
Coroutines.rst [Coroutines] Set presplit attribute in Clang and mlir 2022-01-05 10:25:02 +08:00
CoverageMappingFormat.rst [Coverage] Store compilation dir separately in coverage mapping 2021-02-18 14:34:39 -08:00
CycleTerminology.rst Reapply CycleInfo: Introduce cycles as a generalization of loops 2021-12-10 14:36:43 +05:30
DebuggingJITedCode.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
DeveloperPolicy.rst Documentation for the process of adding new targets 2021-12-28 21:00:26 +00:00
DiscourseMigrationGuide.md Add first draft of the discourse migration guide. 2022-01-07 20:24:35 -08:00
Docker.rst
ExceptionHandling.rst
ExtendedIntegerResults.txt
ExtendingLLVM.rst
Extensions.rst [X86] Selective relocation relaxation for +tagged-globals 2021-11-19 07:18:27 -08:00
FAQ.rst Update references to 'master' branch. 2020-12-21 19:10:34 +00:00
FaultMaps.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
FuzzingLLVM.rst
GarbageCollection.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
GetElementPtr.rst
GettingInvolved.rst [docs] Add Loop Optimization WG to the online sync-up page 2021-11-18 16:49:11 -05:00
GettingStarted.rst Officially deprecate LLVM_ENABLE_PROJECTS for libc++, libc++abi and libunwind 2021-10-29 08:53:03 -04:00
GettingStartedTutorials.rst [docs] Add a new tutorial that talk about how to make a change to llvm 2021-08-30 07:01:04 +00:00
GettingStartedVS.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
GitBisecting.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
GitRepositoryPolicy.md first draft of a written policy around git repos 2021-10-19 08:05:37 +00:00
GoldPlugin.rst
GwpAsan.rst
HowToAddABuilder.rst [docs] Update new builder instructions to starting on the staging buildmaster 2021-12-22 18:21:17 -08:00
HowToBuildOnARM.rst Remove Python2 fallback and only advertise Python3 in the doc 2020-12-17 15:40:16 +01:00
HowToBuildWindowsItaniumPrograms.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
HowToBuildWithPGO.rst docs: Add pointer to cmake caches for PGO 2020-12-07 15:55:26 -05:00
HowToCrossCompileBuiltinsOnArm.rst [test] Migrate -gcc-toolchain with space separator to --gcc-toolchain= 2021-08-20 15:24:58 -07:00
HowToCrossCompileLLVM.rst
HowToReleaseLLVM.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
HowToSetUpLLVMStyleRTTI.rst
HowToSubmitABug.rst docs: update some bug tracker references (NFC) 2022-01-10 15:59:08 -08:00
HowToUpdateDebugInfo.rst Recommit: "[Debugify][Original DI] Test dbg var loc preservation"" 2021-05-21 02:04:29 -07:00
HowToUseAttributes.rst
HowToUseInstrMappings.rst
InAlloca.rst
JITLink.rst Fix some typos in the llvm docs 2021-08-31 21:31:20 +02:00
LangRef.rst Don't override __attribute__((no_stack_protector)) by inlining (PR52886) 2022-01-13 12:04:49 +01:00
Lexicon.rst [llvm] Fix typos in documentation (NFC) 2021-02-27 10:09:23 -08:00
LibFuzzer.rst [libfuzzer] Update doc mentioning removed flags. 2021-05-18 22:40:42 -07:00
LinkTimeOptimization.rst
LoopTerminology.rst [LCSSA] Doc for special treatment of PHIs 2020-10-29 22:50:07 +02:00
MCJIT-creation.png
MCJIT-dyld-load.png
MCJIT-engine-builder.png
MCJIT-load-object.png
MCJIT-load.png
MCJIT-resolve-relocations.png
MCJITDesignAndImplementation.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
MIRLangRef.rst [MIRParser] Add support for IsInlineAsmBrIndirectTarget 2021-10-07 19:08:01 +01:00
MarkdownQuickstartTemplate.md [doc] added section on generating the html doc 2021-08-09 07:27:56 +00:00
MarkedUpDisassembly.rst
MeetupGuidelines.rst
MemTagSanitizer.rst
MemorySSA.rst [MemorySSA] Document details regarding MemorySSA's precision. 2021-12-13 16:49:24 -08:00
MergeFunctions.rst [llvm] Fix typos in documentation (NFC) 2021-02-27 10:09:23 -08:00
MyFirstTypoFix.rst [docs] Update outdated mentions of lab.llvm.org:8011. 2021-11-18 10:51:47 +00:00
NVPTXUsage.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
NewPassManager.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
ORCv2.rst [Docs][ORCv2] GetForCurrentProcess now returns an Expected<std::unique_ptr>. NFC 2021-12-10 14:21:28 -08:00
OpaquePointers.rst [docs][OpaquePtr] Remove finished task 2021-07-14 14:36:41 -07:00
OptBisect.rst
Packaging.rst
Passes.rst Fix some typos in the llvm docs 2021-08-31 21:31:20 +02:00
Phabricator.rst [llvm][docs] Describe how to work with patch series on Phabricator 2021-12-16 15:32:26 +00:00
Phabricator_premerge_results.png [doc] added documentation for pre-merge testing 2021-04-27 16:53:16 +02:00
Phabricator_premerge_unit_tests.png [doc] added documentation for pre-merge testing 2021-04-27 16:53:16 +02:00
PointerAuth.md [IR] Define ptrauth intrinsics. 2021-11-14 07:59:00 -08:00
ProgrammersManual.rst [llvm] Fix small typos in Programmer's Manual and Chrono.h. 2021-12-16 19:20:25 +00:00
Projects.rst [NFC][llvm] Inclusive language: replace master in llvm docs 2021-11-25 13:36:51 -06:00
README.txt Replace references to Makefile.sphinx 2021-10-22 15:32:12 +02:00
Reference.rst [IR] Define ptrauth intrinsics. 2021-11-14 07:59:00 -08:00
ReleaseNotes.rst [lldb] Remove non address bits from memory read arguments 2022-01-11 13:24:09 +00:00
ReleaseProcess.rst
Remarks.rst
ReportingGuide.rst
ScudoHardenedAllocator.rst [llvm] Fix typos in documentation (NFC) 2021-08-28 06:37:03 -07:00
Security.rst Update Pietro Albini's employer 2022-01-12 14:46:06 +01:00
SegmentedStacks.rst
SourceLevelDebugging.rst [llvm] Add support for DW_TAG_immutable_type 2022-01-05 19:17:08 +00:00
SpeculativeLoadHardening.md
SphinxQuickstartTemplate.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
StackMaps.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
StackSafetyAnalysis.rst
Statepoints.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
SupportLibrary.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
SupportPolicy.rst [docs] Adding a Support Policy 2020-11-07 21:06:05 +00:00
SystemLibrary.rst
TableGenFundamentals.rst
TestSuiteGuide.md [docs] Add the compiler-rt requirement to the test suite doc 2021-07-22 16:03:45 -07:00
TestSuiteMakefileGuide.rst
TestingGuide.rst [docs] Mention --leading-lines instead of --no-leading-lines 2021-11-03 10:21:13 -07:00
TransformMetadata.rst
TypeMetadata.rst Update references to 'master' branch. 2020-12-21 19:10:34 +00:00
UserGuides.rst [AMDGPU][NFC] Add documentation for location description DWARF extension 2021-12-14 00:58:17 +00:00
Vectorizers.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
WritingAnLLVMBackend.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
WritingAnLLVMNewPMPass.rst [docs] Add documentation on using the new pass manager 2021-02-26 15:28:19 -08:00
WritingAnLLVMPass.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
XRay.rst [xray] Fix xray document spelling 2021-03-10 16:03:55 +11:00
XRayExample.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
XRayFDRFormat.rst
YamlIO.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
buildbot_worker_contact.png added section on CI system 2021-04-21 09:59:41 +02:00
conf.py [llvm][docs] Bump release number from 12 -> 13 2021-07-01 11:07:03 +00:00
cycle-1.png Reapply CycleInfo: Introduce cycles as a generalization of loops 2021-12-10 14:36:43 +05:30
cycle-2.png Reapply CycleInfo: Introduce cycles as a generalization of loops 2021-12-10 14:36:43 +05:30
cycle-3.png Reapply CycleInfo: Introduce cycles as a generalization of loops 2021-12-10 14:36:43 +05:30
doxygen-mainpage.dox
doxygen.cfg.in [NFC] Inclusive Language: change master to main for .chm files 2021-11-08 08:23:04 -06:00
epilogue-vectorization-cfg.png [LV] Epilogue Vectorization with Optimal Control Flow (Recommit) 2020-12-02 10:09:56 -05:00
gcc-loops.png
index.rst Add first draft of the discourse migration guide. 2022-01-07 20:24:35 -08:00
linpack-pc.png
llvm-objdump.1 [llvm-objdump] Implement --prefix-strip option 2021-03-24 13:22:35 +00:00
loop-guard.svg [docs] Revise loop terminology reference. 2020-10-05 10:28:04 -05:00
loop-irreducible.svg [docs] Revise loop terminology reference. 2020-10-05 10:28:04 -05:00
loop-merge.svg [docs] Revise loop terminology reference. 2020-10-05 10:28:04 -05:00
loop-nested.svg [docs] Revise loop terminology reference. 2020-10-05 10:28:04 -05:00
loop-nonmaximal.svg [docs] Revise loop terminology reference. 2020-10-05 10:28:04 -05:00
loop-separate.svg [docs] Revise loop terminology reference. 2020-10-05 10:28:04 -05:00
loop-single.svg [docs] Revise loop terminology reference. 2020-10-05 10:28:04 -05:00
loop-terminology-guarded-loop.png
loop-terminology-initial-loop.png
loop-terminology-rotated-loop.png
loop-terminology.svg [docs] Revise loop terminology reference. 2020-10-05 10:28:04 -05:00
make.bat
re_format.7
speculative_load_hardening_microbenchmarks.png
yaml2obj.rst

README.txt

LLVM Documentation
==================

LLVM's documentation is written in reStructuredText, a lightweight
plaintext markup language (file extension `.rst`). While the
reStructuredText documentation should be quite readable in source form, it
is mostly meant to be processed by the Sphinx documentation generation
system to create HTML pages which are hosted on <https://llvm.org/docs/> and
updated after every commit. Manpage output is also supported, see below.

If you instead would like to generate and view the HTML locally, install
Sphinx <http://sphinx-doc.org/> and then do:

    cd <build-dir>
    cmake -DLLVM_ENABLE_SPHINX=true -DSPHINX_OUTPUT_HTML=true <src-dir>
    make -j3 docs-llvm-html
    $BROWSER <build-dir>/docs/html/index.html

The mapping between reStructuredText files and generated documentation is
`docs/Foo.rst` <-> `<build-dir>/docs//html/Foo.html` <-> `https://llvm.org/docs/Foo.html`.

If you are interested in writing new documentation, you will want to read
`SphinxQuickstartTemplate.rst` which will get you writing documentation
very fast and includes examples of the most important reStructuredText
markup syntax.

Manpage Output
===============

Building the manpages is similar to building the HTML documentation. The
primary difference is to use the `man` makefile target, instead of the
default (which is `html`). Sphinx then produces the man pages in the
directory `<build-dir>/docs/man/`.

    cd <build-dir>
    cmake -DLLVM_ENABLE_SPHINX=true -DSPHINX_OUTPUT_MAN=true <src-dir>
    make -j3 docs-llvm-man
    man -l <build-dir>/docs/man/FileCheck.1

The correspondence between .rst files and man pages is
`docs/CommandGuide/Foo.rst` <-> `<build-dir>/docs//man/Foo.1`.
These .rst files are also included during HTML generation so they are also
viewable online (as noted above) at e.g.
`https://llvm.org/docs/CommandGuide/Foo.html`.

Checking links
==============

The reachability of external links in the documentation can be checked by
running:

    cd llvm/docs/
    sphinx-build -b linkcheck . _build/lintcheck/
    # report will be generated in _build/lintcheck/output.txt

Doxygen page Output
==============

Install doxygen <https://www.doxygen.nl/download.html> and dot2tex <https://dot2tex.readthedocs.io/en/latest>.

    cd <build-dir>
    cmake -DLLVM_ENABLE_DOXYGEN=On <llvm-top-src-dir>
    make doxygen-llvm # for LLVM docs
    make doxygen-clang # for clang docs

It will generate html in

    <build-dir>/docs/doxygen/html # for LLVM docs
    <build-dir>/tools/clang/docs/doxygen/html # for clang docs