From f3888ba23ff0e08c7091cd4a8a61a267a99eadc7 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Sun, 1 Mar 2009 21:55:10 +0000 Subject: [PATCH] Add a quickstart example. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65789 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/GoldPlugin.html | 57 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/docs/GoldPlugin.html b/docs/GoldPlugin.html index 1a2268f4f72..a16b1101ad1 100644 --- a/docs/GoldPlugin.html +++ b/docs/GoldPlugin.html @@ -11,7 +11,10 @@
  1. Introduction
  2. How to build it
  3. -
  4. Usage
  5. +
  6. Usage +
  7. Licensing
Written by Nick Lewycky
@@ -80,6 +83,58 @@ make all-gold linker, which is why you need gold to be the installed system linker in your path.

+ + +
+ Example of link time optimization +
+ +
+

The following example shows a worked example of the gold plugin mixing + LLVM bitcode and native code. +

+--- a.c ---
+#include <stdio.h>
+
+extern void foo1(void);
+extern void foo4(void);
+
+void foo2(void) {
+  printf("Foo2\n");
+}
+
+void foo3(void) {
+  foo4();
+}
+
+int main(void) {
+  foo1();
+}
+
+--- b.c ---
+#include <stdio.h>
+
+extern void foo2(void);
+
+void foo1(void) {
+  foo2();
+}
+
+void foo4(void) {
+  printf("Foo4");
+}
+
+--- command lines ---
+$ llvm-gcc -flto a.c -c -o a.o              # <-- a.o is LLVM bitcode file
+$ llvm-gcc b.c -c -o b.o                    # <-- b.o is native object file
+$ llvm-gcc -use-gold-plugin a.o b.o -o main # <-- link with LLVMgold plugin
+
+

Gold informs the plugin that foo3 is never referenced outside the IR, + leading LLVM to delete that function. However, unlike in the + libLTO + example gold does not currently eliminate foo4.

+
+
Licensing