[llvm] 114325b - Kaleidoscope-Ch8: use Reloc::PIC_

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 5 23:44:39 PST 2023


Author: Fangrui Song
Date: 2023-12-05T23:44:35-08:00
New Revision: 114325b86a3d0360afc772c44335fc9092686f58

URL: https://github.com/llvm/llvm-project/commit/114325b86a3d0360afc772c44335fc9092686f58
DIFF: https://github.com/llvm/llvm-project/commit/114325b86a3d0360afc772c44335fc9092686f58.diff

LOG: Kaleidoscope-Ch8: use Reloc::PIC_

which has better portability across different OSes.
In addition, on many ELF OSes, this output relocatable file can be
linked without -no-pie.

Added: 
    

Modified: 
    llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl08.rst
    llvm/examples/Kaleidoscope/Chapter8/toy.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl08.rst b/llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl08.rst
index 33ee7d209d4c5..17bf8a47c84c7 100644
--- a/llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl08.rst
+++ b/llvm/docs/tutorial/MyFirstLanguageFrontend/LangImpl08.rst
@@ -105,8 +105,8 @@ To see which features and CPUs that LLVM knows about, we can use
       3dnowa                - Enable 3DNow! Athlon instructions.
       ...
 
-For our example, we'll use the generic CPU without any additional
-features, options or relocation model.
+For our example, we'll use the generic CPU without any additional feature or
+target option.
 
 .. code-block:: c++
 
@@ -114,8 +114,7 @@ features, options or relocation model.
   auto Features = "";
 
   TargetOptions opt;
-  auto RM = std::optional<Reloc::Model>();
-  auto TargetMachine = Target->createTargetMachine(TargetTriple, CPU, Features, opt, RM);
+  auto TargetMachine = Target->createTargetMachine(TargetTriple, CPU, Features, opt, Reloc::PIC_);
 
 
 Configuring the Module

diff  --git a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
index 1d36a7e67e3d2..ae2f9c7059e5f 100644
--- a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp
@@ -1242,9 +1242,8 @@ int main() {
   auto Features = "";
 
   TargetOptions opt;
-  auto RM = std::optional<Reloc::Model>();
-  auto TheTargetMachine =
-      Target->createTargetMachine(TargetTriple, CPU, Features, opt, RM);
+  auto TheTargetMachine = Target->createTargetMachine(
+      TargetTriple, CPU, Features, opt, Reloc::PIC_);
 
   TheModule->setDataLayout(TheTargetMachine->createDataLayout());
 


        


More information about the llvm-commits mailing list