set(LLD_TEST_DEPS lld)
if (NOT LLD_BUILT_STANDALONE)
list(APPEND LLD_TEST_DEPS
- FileCheck count extract llc llvm-ar llvm-as llvm-bcanalyzer llvm-config llvm-cvtres
+ FileCheck count llc llvm-ar llvm-as llvm-bcanalyzer llvm-config llvm-cvtres
llvm-dis llvm-dwarfdump llvm-lib llvm-lipo llvm-mc llvm-nm llvm-objcopy
llvm-objdump llvm-pdbutil llvm-readelf llvm-readobj llvm-strip not obj2yaml
opt yaml2obj
# REQUIRES: x86
-# RUN: extract asm %s -o %t.s && extract lds %s -o %t.lds
-# RUN: llvm-mc -filetype=obj -triple=x86_64 %t.s -o %t.o
-# RUN: ld.lld -o %t --script %t.lds %t.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "SECTIONS { \
+# RUN: .data_noload_a (NOLOAD) : { *(.data_noload_a) } \
+# RUN: .data_noload_b (0x10000) (NOLOAD) : { *(.data_noload_b) } \
+# RUN: .no_input_sec_noload (NOLOAD) : { . += 1; } \
+# RUN: .text (0x20000) : { *(.text) } };" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o
# RUN: llvm-readelf -S -l %t | FileCheck %s
# CHECK: Name Type Address Off Size
# CHECK: Type Offset VirtAddr PhysAddr
# CHECK-NEXT: LOAD 0x001000 0x0000000000020000 0x0000000000020000
-#--- asm
.section .text,"ax",@progbits
nop
.section .data_noload_b,"aw",@progbits
.zero 4096
-
-#--- lds
-SECTIONS {
- .data_noload_a (NOLOAD) : { *(.data_noload_a) }
- .data_noload_b (0x10000) (NOLOAD) : { *(.data_noload_b) }
- .no_input_sec_noload (NOLOAD) : { . += 1; }
- .text (0x20000) : { *(.text) }
-}
llvm_config.use_lld()
tool_patterns = [
- 'extract', 'llc', 'llvm-as', 'llvm-mc', 'llvm-nm', 'llvm-objdump',
- 'llvm-pdbutil', 'llvm-dwarfdump', 'llvm-readelf', 'llvm-readobj',
- 'obj2yaml', 'yaml2obj', 'opt', 'llvm-dis']
+ 'llc', 'llvm-as', 'llvm-mc', 'llvm-nm', 'llvm-objdump', 'llvm-pdbutil',
+ 'llvm-dwarfdump', 'llvm-readelf', 'llvm-readobj', 'obj2yaml', 'yaml2obj',
+ 'opt', 'llvm-dis']
llvm_config.add_tool_substitutions(tool_patterns)
# Indirectly check if the mt.exe Microsoft utility exists by searching for
# cvtres, which always accompanies it. Alternatively, check if we can use
# libxml2 to merge manifests.
-if (lit.util.which('cvtres', config.environment['PATH']) or
+if (lit.util.which('cvtres', config.environment['PATH']) or
config.llvm_libxml2_enabled):
config.available_features.add('manifest_tool')
Extra files
-----------
-If your test requires extra files besides the file containing the ``RUN:`` lines
-and the extra files are small, consider specifying them in the same file and
-using ``extract`` to extract them. For example,
-
-.. code-block:: llvm
-
- ; RUN: extract b %s -o %tb.ll
- ; RUN: extract a %s | llvm-link - %tb.ll -S | FileCheck %s
-
- ; CHECK: ...
-
- ;--- a
- ...
- ;--- b
- ...
-
-The parts are separated by the regex ``^(.|//)--- <part>``. By default the
-extracted content has leading empty lines to preserve line numbers. Specify
-``--no-leading-lines`` to drop leading lines.
-
-If the extra files are large, the idiomatic place to put them is in a subdirectory ``Inputs``.
+If your test requires extra files besides the file containing the ``RUN:``
+lines, the idiomatic place to put them is in a subdirectory ``Inputs``.
You can then refer to the extra files as ``%S/Inputs/foo.bar``.
For example, consider ``test/Linker/ident.ll``. The directory structure is
UnitTests
bugpoint
count
- extract
llc
lli
lli-child-target
config.llvm_locstats_used = os.path.exists(llvm_locstats_tool)
tools = [
- ToolSubst('%extract', FindTool('extract')),
ToolSubst('%lli', FindTool('lli'), post='.', extra_args=lli_args),
ToolSubst('%llc_dwarf', FindTool('llc'), extra_args=llc_args),
ToolSubst('%go', config.go_executable, unresolved='ignore'),
+++ /dev/null
-
-
-
-aa
-; BB-NOT: {{.}}
-; BB: {{^}}bb{{$}}
+++ /dev/null
-
-
-
-
-
-
-
-bb
-
-// CC: // Comments are preserved.
+++ /dev/null
-# AA-NOT: {{.}}
-# AA: {{^}}aa{{$}}
-#--- aa
-aa
-; BB-NOT: {{.}}
-; BB: {{^}}bb{{$}}
-;--- bb
-bb
-
-// CC: // Comments are preserved.
-//--- cc
-cc
-// Comments are preserved.
-;--- dup
-;--- dup
-
-# RUN: extract aa %s | diff %S/Inputs/basic-aa.txt -
-# RUN: extract bb - < %s | diff %S/Inputs/basic-bb.txt -
-# RUN: extract cc %s -o %t
-# RUN: FileCheck %s --check-prefix=CC < %t
-
-# RUN: not %extract aa 2>&1 | FileCheck %s --check-prefix=NO_INPUT
-
-# NO_INPUT: extract: error: input filename is not specified
-
-# RUN: not %extract dup %s 2>&1 | FileCheck %s --check-prefix=DUP
-
-# DUP: extract: error: {{.*}}.test: ';--- dup' occurs more than once
-
-# RUN: not %extract not_exist %s 2>&1 | FileCheck %s --check-prefix=NOT_EXIST
-
-# NOT_EXIST: extract: error: {{.*}}.test: ';--- not_exist' was not found
+++ /dev/null
-RUN: extract --help 2>&1 | FileCheck --implicit-check-not='General Options:' %s
-CHECK: OVERVIEW: Split input {{.*}}
-CHECK: Generic Options:
-CHECK: extract Options:
-CHECK: -o
+++ /dev/null
-## With --no-leading-lines, don't add leading lines (which is used to preserve line numbers).
-
-# RUN: extract --no-leading-lines input %s -o %t
-# RUN: count 1 < %t
-# RUN: FileCheck %s < %t
-
-# CHECK: input
-
-#--- input
-input
-; RUN: extract order %s -o %t.order
-; RUN: extract ir %s | llvm-as -o %t.o
+; RUN: echo ".text.tin" > %t_order_lto.txt
+; RUN: echo ".text._start" >> %t_order_lto.txt
+; RUN: echo ".text.pat" >> %t_order_lto.txt
+; RUN: llvm-as %s -o %t.o
; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \
; RUN: -m elf_x86_64 -o %t.exe %t.o \
-; RUN: --section-ordering-file=%t.order
+; RUN: --section-ordering-file=%t_order_lto.txt
; RUN: llvm-readelf -s %t.exe | FileCheck %s
; Check that the order of the sections is tin -> _start -> pat.
; CHECK: 00000000004000b0 1 FUNC LOCAL DEFAULT 1 tin
; CHECK: 00000000004000c0 15 FUNC GLOBAL DEFAULT 1 _start
-;--- order
-.text.tin
-.text._start
-.text.pat
-
-;--- ir
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
-# RUN: extract yaml %s | yaml2obj - -o %t
+# RUN: yaml2obj %s -o %t
# RUN: llvm-objcopy --strip-symbol baz -N bar %t %t2
# RUN: llvm-readobj --symbols --sections %t2 | FileCheck %s
# RUN: llvm-strip --strip-symbol baz -N bar %t -o %t3
# RUN: cmp %t2 %t3
# RUN: llvm-strip --regex --strip-symbol '^b.*' -N bar %t -o %t4
# RUN: cmp %t3 %t4
-# RUN: extract list1 %s -o %t-list.txt && llvm-objcopy --strip-symbols %t-list.txt %t %t5
+# RUN: echo " bar # bar" > %t-list.txt
+# RUN: echo " baz # baz" >> %t-list.txt
+# RUN: echo " # no symbol" >> %t-list.txt
+# RUN: llvm-objcopy --strip-symbols %t-list.txt %t %t5
# RUN: cmp %t3 %t5
-# RUN: extract list2 %s -o %t-list2.txt && llvm-objcopy --regex --strip-symbols %t-list2.txt %t %t6
+# RUN: echo "b.* # bar & baz" > %t-list2.txt
+# RUN: llvm-objcopy --regex --strip-symbols %t-list2.txt %t %t6
# RUN: cmp %t3 %t6
-#--- list1
-bar # bar
-baz # baz
-# no symbol
-
-#--- list2
-b.* # bar & baz
-
-#--- yaml
!ELF
FileHeader:
Class: ELFCLASS64
## Show that llvm-strings can handle the -t/--radix switch properly.
-RUN: extract --no-leading-lines input %s -o %t
-#--- input
-one
-two
-three
-four
-five
-six
-seven
-eight
-nine
-ten
-#--- end
+RUN: echo one > %t
+RUN: echo two >> %t
+RUN: echo three >> %t
+RUN: echo four >> %t
+RUN: echo five >> %t
+RUN: echo six >> %t
+RUN: echo seven >> %t
+RUN: echo eight >> %t
+RUN: echo nine >> %t
+RUN: echo ten >> %t
RUN: llvm-strings %t | FileCheck %s -check-prefix CHECK-NONE --implicit-check-not={{.}}
RUN: llvm-strings -t d %t | FileCheck %s -check-prefix CHECK-DEC --strict-whitespace --implicit-check-not={{.}}
+++ /dev/null
-# Almost identical to the top-level .clang-tidy, except that {Member,Parameter,Variable}Case use camelBack.
-Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,readability-identifier-naming'
-CheckOptions:
- - key: readability-identifier-naming.ClassCase
- value: CamelCase
- - key: readability-identifier-naming.EnumCase
- value: CamelCase
- - key: readability-identifier-naming.FunctionCase
- value: camelBack
- - key: readability-identifier-naming.MemberCase
- value: camelBack
- - key: readability-identifier-naming.ParameterCase
- value: camelBack
- - key: readability-identifier-naming.UnionCase
- value: CamelCase
- - key: readability-identifier-naming.VariableCase
- value: camelBack
- - key: readability-identifier-naming.IgnoreMainLikeFunctions
- value: 1
+++ /dev/null
-set(LLVM_LINK_COMPONENTS
- Support
- )
-
-add_llvm_tool(extract
- extract.cpp
- )
+++ /dev/null
-//===- extract.cpp - Input splitting utility ------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-//
-// Split input into multipe parts separated by regex '^(.|//)--- ' and extract
-// the specified part.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/FileOutputBuffer.h"
-#include "llvm/Support/LineIterator.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Support/WithColor.h"
-#include <string>
-
-using namespace llvm;
-
-static cl::OptionCategory cat("extract Options");
-
-static cl::opt<std::string> part(cl::Positional, cl::desc("part"),
- cl::cat(cat));
-
-static cl::opt<std::string> input(cl::Positional, cl::desc("filename"),
- cl::cat(cat));
-
-static cl::opt<std::string> output("o", cl::desc("Output filename"),
- cl::value_desc("filename"), cl::init("-"),
- cl::cat(cat));
-
-static cl::opt<bool> noLeadingLines("no-leading-lines",
- cl::desc("Don't preserve line numbers"),
- cl::cat(cat));
-
-static StringRef toolName;
-
-LLVM_ATTRIBUTE_NORETURN static void error(StringRef filename,
- const Twine &message) {
- if (filename.empty())
- WithColor::error(errs(), toolName) << message << '\n';
- else
- WithColor::error(errs(), toolName) << filename << ": " << message << '\n';
- exit(1);
-}
-
-static void handle(MemoryBuffer &inputBuf, StringRef input) {
- const char *partBegin = nullptr, *partEnd = nullptr;
- int numEmptyLines = 0;
- StringRef separator;
- for (line_iterator i(inputBuf, /*SkipBlanks=*/false, '\0'); !i.is_at_eof();) {
- StringRef line = *i++;
- size_t markerLen = line.startswith("//") ? 6 : 5;
- if (!(line.size() > markerLen &&
- line.substr(markerLen - 4).startswith("--- ")))
- continue;
- separator = line.substr(0, markerLen);
- StringRef cur = line.substr(markerLen);
- if (cur == part) {
- if (partBegin)
- error(input, "'" + separator + cur + "' occurs more than once");
- if (!noLeadingLines)
- numEmptyLines = i.line_number() - 1;
- if (i.is_at_eof())
- break;
- partBegin = i->data();
- } else if (partBegin && !partEnd) {
- partEnd = line.data();
- }
- }
- if (!partBegin)
- error(input, "'" + separator + part + "' was not found");
- if (!partEnd)
- partEnd = inputBuf.getBufferEnd();
-
- Expected<std::unique_ptr<FileOutputBuffer>> outputBuf =
- FileOutputBuffer::create(output, numEmptyLines + (partEnd - partBegin));
- if (!outputBuf)
- error(input, toString(outputBuf.takeError()));
- uint8_t *buf = (*outputBuf)->getBufferStart();
-
- // If --no-leading-lines is not specified, numEmptyLines is 0. Append newlines
- // so that the extracted part preserves line numbers.
- std::fill_n(buf, numEmptyLines, '\n');
- std::copy(partBegin, partEnd, buf + numEmptyLines);
- if (Error e = (*outputBuf)->commit())
- error(input, toString(std::move(e)));
-}
-
-int main(int argc, const char **argv) {
- toolName = sys::path::stem(argv[0]);
- cl::HideUnrelatedOptions({&cat});
- cl::ParseCommandLineOptions(
- argc, argv,
- "Split input into multiple parts separated by regex '^(.|//)--- ' and "
- "extract the part specified by '^(.|//)--- <part>'\n",
- nullptr,
- /*EnvVar=*/nullptr,
- /*LongOptionsUseDoubleDash=*/true);
-
- if (input.empty())
- error("", "input filename is not specified");
- ErrorOr<std::unique_ptr<MemoryBuffer>> bufferOrErr =
- MemoryBuffer::getFileOrSTDIN(input);
- if (std::error_code ec = bufferOrErr.getError())
- error(input, ec.message());
- handle(**bufferOrErr, input);
-}