[llvm] 6c43ed6 - Introducing llvm-libtool-darwin

Sameer Arora via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 17 08:07:59 PDT 2020


Author: Sameer Arora
Date: 2020-07-17T08:07:02-07:00
New Revision: 6c43ed608d5de84f0d17960b2b449a4a7fc0ca2a

URL: https://github.com/llvm/llvm-project/commit/6c43ed608d5de84f0d17960b2b449a4a7fc0ca2a
DIFF: https://github.com/llvm/llvm-project/commit/6c43ed608d5de84f0d17960b2b449a4a7fc0ca2a.diff

LOG: Introducing llvm-libtool-darwin

This diff starts the implementation of llvm-libtool-darwin
(an llvm based replacement of cctool's libtool).
Libtool is used for creating static and dynamic libraries
from a bunch of object files given as input.

Reviewed by alexshap, smeenai, jhenderson, MaskRay

Differential Revision: https://reviews.llvm.org/D82923

Added: 
    llvm/docs/CommandGuide/llvm-libtool-darwin.rst
    llvm/test/tools/llvm-libtool-darwin/Inputs/input1.yaml
    llvm/test/tools/llvm-libtool-darwin/Inputs/input2.yaml
    llvm/test/tools/llvm-libtool-darwin/basic.test
    llvm/test/tools/llvm-libtool-darwin/help-message.test
    llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test
    llvm/tools/llvm-libtool-darwin/CMakeLists.txt
    llvm/tools/llvm-libtool-darwin/LLVMBuild.txt
    llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp

Modified: 
    llvm/docs/CommandGuide/index.rst
    llvm/test/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CommandGuide/index.rst b/llvm/docs/CommandGuide/index.rst
index 77fece030eb6..d13c2a0fc0a9 100644
--- a/llvm/docs/CommandGuide/index.rst
+++ b/llvm/docs/CommandGuide/index.rst
@@ -14,25 +14,26 @@ Basic Commands
 .. toctree::
    :maxdepth: 1
 
-   llvm-as
-   llvm-dis
-   opt
+   dsymutil
    llc
    lli
-   llvm-link
-   llvm-lib
-   llvm-lipo
+   llvm-as
    llvm-config
+   llvm-cov
    llvm-cxxmap
    llvm-
diff 
-   llvm-cov
-   llvm-profdata
-   llvm-stress
-   llvm-symbolizer
+   llvm-dis
    llvm-dwarfdump
-   dsymutil
+   llvm-lib
+   llvm-libtool-darwin
+   llvm-link
+   llvm-lipo
    llvm-mca
+   llvm-profdata
    llvm-readobj
+   llvm-stress
+   llvm-symbolizer
+   opt
 
 GNU binutils replacements
 ~~~~~~~~~~~~~~~~~~~~~~~~~

diff  --git a/llvm/docs/CommandGuide/llvm-libtool-darwin.rst b/llvm/docs/CommandGuide/llvm-libtool-darwin.rst
new file mode 100644
index 000000000000..0baacfd88e8a
--- /dev/null
+++ b/llvm/docs/CommandGuide/llvm-libtool-darwin.rst
@@ -0,0 +1,59 @@
+llvm-libtool-darwin - LLVM tool for creating libraries for Darwin
+=================================================================
+
+.. program:: llvm-libtool-darwin
+
+SYNOPSIS
+--------
+
+:program:`llvm-libtool-darwin` [*options*] *<input files>*
+
+DESCRIPTION
+-----------
+
+:program:`llvm-libtool-darwin` is a tool for creating static and dynamic
+libraries for Darwin.
+
+For most scenarios, it works as a drop-in replacement for cctools'
+:program:`libtool`.
+
+OPTIONS
+--------
+:program:`llvm-libtool-darwin` supports the following options:
+
+.. option:: -h, -help
+
+  Show help and usage for this command.
+
+.. option:: -help-list
+
+  Show help and usage for this command without grouping the options
+  into categories.
+
+.. option:: -color
+
+  Use colors in output.
+
+.. option:: -version
+
+  Display the version of this program.
+
+.. option:: -o <filename>
+
+  Specify the output file name. Must be specified exactly once.
+
+EXIT STATUS
+-----------
+
+:program:`llvm-libtool-darwin` exits with a non-zero exit code if there is an error.
+Otherwise, it exits with code 0.
+
+BUGS
+----
+
+To report bugs, please visit <https://bugs.llvm.org/>.
+
+SEE ALSO
+--------
+
+:manpage:`llvm-ar(1)`

diff  --git a/llvm/test/CMakeLists.txt b/llvm/test/CMakeLists.txt
index b0a0a259d741..6994c29efa9a 100644
--- a/llvm/test/CMakeLists.txt
+++ b/llvm/test/CMakeLists.txt
@@ -83,6 +83,7 @@ set(LLVM_TEST_DEPENDS
           llvm-install-name-tool
           llvm-jitlink
           llvm-lib
+          llvm-libtool-darwin
           llvm-link
           llvm-lipo
           llvm-locstats

diff  --git a/llvm/test/tools/llvm-libtool-darwin/Inputs/input1.yaml b/llvm/test/tools/llvm-libtool-darwin/Inputs/input1.yaml
new file mode 100644
index 000000000000..185f21c8b736
--- /dev/null
+++ b/llvm/test/tools/llvm-libtool-darwin/Inputs/input1.yaml
@@ -0,0 +1,56 @@
+# int symbol1() {
+#   return 0;
+# }
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACF
+  cputype:         0x01000007
+  cpusubtype:      0x00000003
+  filetype:        0x00000001
+  ncmds:           2
+  sizeofcmds:      176
+  flags:           0x00002000
+  reserved:        0x00000000
+LoadCommands:
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         152
+    segname:         ''
+    vmaddr:          0
+    vmsize:          8
+    fileoff:         312
+    filesize:        8
+    maxprot:         7
+    initprot:        7
+    nsects:          1
+    flags:           0
+    Sections:
+      - sectname:        __text
+        segname:         __TEXT
+        addr:            0x0000000000000000
+        size:            8
+        offset:          0x00000138
+        align:           4
+        reloff:          0x00000000
+        nreloc:          0
+        flags:           0x80000400
+        reserved1:       0x00000000
+        reserved2:       0x00000000
+        reserved3:       0x00000000
+        content:         554889E531C05DC3
+  - cmd:             LC_SYMTAB
+    cmdsize:         24
+    symoff:          320
+    nsyms:           1
+    stroff:          336
+    strsize:         8
+LinkEditData:
+  NameList:
+    - n_strx:          1
+      n_type:          0x0F
+      n_sect:          1
+      n_desc:          0
+      n_value:         0
+  StringTable:
+    - ''
+    - _symbol1
+...

diff  --git a/llvm/test/tools/llvm-libtool-darwin/Inputs/input2.yaml b/llvm/test/tools/llvm-libtool-darwin/Inputs/input2.yaml
new file mode 100644
index 000000000000..521ef93ae23b
--- /dev/null
+++ b/llvm/test/tools/llvm-libtool-darwin/Inputs/input2.yaml
@@ -0,0 +1,57 @@
+# int symbol2() {
+#   return 0;
+# }
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACF
+  cputype:         0x01000007
+  cpusubtype:      0x00000003
+  filetype:        0x00000001
+  ncmds:           2
+  sizeofcmds:      176
+  flags:           0x00002000
+  reserved:        0x00000000
+LoadCommands:
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         152
+    segname:         ''
+    vmaddr:          0
+    vmsize:          15
+    fileoff:         312
+    filesize:        15
+    maxprot:         7
+    initprot:        7
+    nsects:          1
+    flags:           0
+    Sections:
+      - sectname:        __text
+        segname:         __TEXT
+        addr:            0x0000000000000000
+        size:            15
+        offset:          0x00000138
+        align:           4
+        reloff:          0x00000000
+        nreloc:          0
+        flags:           0x80000400
+        reserved1:       0x00000000
+        reserved2:       0x00000000
+        reserved3:       0x00000000
+        content:         554889E531C0C745FC000000005DC3
+  - cmd:             LC_SYMTAB
+    cmdsize:         24
+    symoff:          328
+    nsyms:           1
+    stroff:          344
+    strsize:         8
+LinkEditData:
+  NameList:
+    - n_strx:          1
+      n_type:          0x0F
+      n_sect:          1
+      n_desc:          0
+      n_value:         0
+  StringTable:
+    - ''
+    - _symbol2
+    - ''
+...

diff  --git a/llvm/test/tools/llvm-libtool-darwin/basic.test b/llvm/test/tools/llvm-libtool-darwin/basic.test
new file mode 100644
index 000000000000..5cb6fea899bf
--- /dev/null
+++ b/llvm/test/tools/llvm-libtool-darwin/basic.test
@@ -0,0 +1,10 @@
+## This test checks that main exits normally (error code 0) for correct input/output args.
+
+# RUN: yaml2obj %S/Inputs/input1.yaml -o %t-input1.o
+# RUN: yaml2obj %S/Inputs/input2.yaml -o %t-input2.o
+
+## Pass single input:
+# RUN: llvm-libtool-darwin -o %t.lib %t-input1.o
+
+## Pass multiple inputs:
+# RUN: llvm-libtool-darwin -o %t.lib %t-input1.o %t-input2.o

diff  --git a/llvm/test/tools/llvm-libtool-darwin/help-message.test b/llvm/test/tools/llvm-libtool-darwin/help-message.test
new file mode 100644
index 000000000000..4face3887ed2
--- /dev/null
+++ b/llvm/test/tools/llvm-libtool-darwin/help-message.test
@@ -0,0 +1,23 @@
+## This test checks that the help message is displayed correctly.
+
+# RUN: llvm-libtool-darwin -h | FileCheck --check-prefixes=LIBTOOL-USAGE,CATEG %s --match-full-lines
+# RUN: llvm-libtool-darwin -help | FileCheck --check-prefixes=LIBTOOL-USAGE,CATEG %s --match-full-lines
+# RUN: llvm-libtool-darwin --help | FileCheck --check-prefixes=LIBTOOL-USAGE,CATEG %s --match-full-lines
+# RUN: llvm-libtool-darwin --help-list | \
+# RUN:   FileCheck -check-prefixes=LIBTOOL-USAGE,LIST %s --match-full-lines
+
+# RUN: not llvm-libtool-darwin -abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s
+# RUN: not llvm-libtool-darwin --abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s
+
+# LIBTOOL-USAGE: OVERVIEW: llvm-libtool-darwin
+# LIBTOOL-USAGE: USAGE: llvm-libtool-darwin{{(\.exe)?}} [options] <input files>
+# LIBTOOL-USAGE: OPTIONS:
+
+# CATEG:    Color Options:
+# LIST-NOT: Color Options:
+# CATEG:    Generic Options:
+# LIST-NOT: Generic Options:
+# CATEG:    llvm-libtool-darwin Options:
+# LIST-NOT: llvm-libtool-darwin Options:
+
+# UNKNOWN-ARG: Unknown command line argument '{{-+}}abcabc'

diff  --git a/llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test b/llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test
new file mode 100644
index 000000000000..5b4d2d988ae4
--- /dev/null
+++ b/llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test
@@ -0,0 +1,25 @@
+## This test checks that an error is thrown in case of invalid input/output args.
+
+## Missing input file:
+# RUN: not llvm-libtool-darwin -o %t.lib 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=NO-INPUT
+
+# NO-INPUT: Must specify at least 1 positional argument
+
+## Missing output file:
+# RUN: not llvm-libtool-darwin %t.input 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=NO-OUTPUT
+
+# NO-OUTPUT: for the -o option: must be specified at least once!
+
+## Missing argument to -o:
+# RUN: not llvm-libtool-darwin %t.input -o 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=MISSING
+
+# MISSING: for the -o option: requires a value!
+
+## Passing in two output files:
+# RUN: not llvm-libtool-darwin %t.input -o %t.lib1 -o %t.lib2 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=DOUBLE-OUTPUT
+
+# DOUBLE-OUTPUT: for the -o option: must occur exactly one time!

diff  --git a/llvm/tools/llvm-libtool-darwin/CMakeLists.txt b/llvm/tools/llvm-libtool-darwin/CMakeLists.txt
new file mode 100644
index 000000000000..b2ea63a8da49
--- /dev/null
+++ b/llvm/tools/llvm-libtool-darwin/CMakeLists.txt
@@ -0,0 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_llvm_tool(llvm-libtool-darwin
+  llvm-libtool-darwin.cpp
+)

diff  --git a/llvm/tools/llvm-libtool-darwin/LLVMBuild.txt b/llvm/tools/llvm-libtool-darwin/LLVMBuild.txt
new file mode 100644
index 000000000000..3858d2faa778
--- /dev/null
+++ b/llvm/tools/llvm-libtool-darwin/LLVMBuild.txt
@@ -0,0 +1,20 @@
+;===- ./tools/llvm-libtool-darwin/LVMBuild.txt -----------------*- Conf -*--===;
+;
+; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+; See https://llvm.org/LICENSE.txt for license information.
+; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+;
+;===------------------------------------------------------------------------===;
+;
+; This is an LLVMBuild description file for the components in this subdirectory.
+;
+; For more information on the LLVMBuild system, please see:
+;
+;   http://llvm.org/docs/LLVMBuild.html
+;
+;===------------------------------------------------------------------------===;
+[component_0]
+type = Tool
+name = llvm-libtool-darwin
+parent = Tools
+required_libraries = Support

diff  --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
new file mode 100644
index 000000000000..bc2f9f765f43
--- /dev/null
+++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -0,0 +1,34 @@
+//===-- llvm-libtool-darwin.cpp - a tool for creating libraries -----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// A utility for creating static and dynamic libraries for Darwin.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/InitLLVM.h"
+#include "llvm/Support/WithColor.h"
+
+using namespace llvm;
+
+cl::OptionCategory LibtoolCategory("llvm-libtool-darwin Options");
+
+static cl::opt<std::string> OutputFile("o", cl::desc("Specify output filename"),
+                                       cl::value_desc("filename"), cl::Required,
+                                       cl::cat(LibtoolCategory));
+
+static cl::list<std::string> InputFiles(cl::Positional,
+                                        cl::desc("<input files>"),
+                                        cl::OneOrMore,
+                                        cl::cat(LibtoolCategory));
+
+int main(int Argc, char **Argv) {
+  InitLLVM X(Argc, Argv);
+  cl::HideUnrelatedOptions({&LibtoolCategory, &ColorCategory});
+  cl::ParseCommandLineOptions(Argc, Argv, "llvm-libtool-darwin\n");
+}


        


More information about the llvm-commits mailing list