Unverified Commit 8570713a authored by Georg Koppen's avatar Georg Koppen
Browse files

Bug 34386: Fix up clang compilation on Linux

We can't build the crt in the compiler-rt project on Linux anymore and
work around it by disabling that part. This is likely yet another sign
of Debian Wheezy showing its age.

Apart from that, we should use our own binutils and not whatever Wheezy
is providing.
parent f1fdc912
From 3757213db371dcea53cae357cf9c56d1b0604f98 Mon Sep 17 00:00:00 2001
From: Alina Sbirlea <asbirlea@google.com>
Date: Fri, 12 Jul 2019 22:30:30 +0000
Subject: [PATCH] [MemorySSA] Use SetVector to avoid nondeterminism.
Summary:
Use a SetVector for DeadBlockSet.
Resolves PR42574.
Reviewers: george.burgess.iv, uabelho, dblaikie
Subscribers: jlebar, Prazek, mgrang, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64601
llvm-svn: 365970
diff --git a/llvm/include/llvm/Analysis/MemorySSAUpdater.h b/llvm/include/llvm/Analysis/MemorySSAUpdater.h
index 169d5bd9fa8..276620bd445 100644
--- a/llvm/include/llvm/Analysis/MemorySSAUpdater.h
+++ b/llvm/include/llvm/Analysis/MemorySSAUpdater.h
@@ -32,6 +32,7 @@
#ifndef LLVM_ANALYSIS_MEMORYSSAUPDATER_H
#define LLVM_ANALYSIS_MEMORYSSAUPDATER_H
+#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
@@ -239,7 +240,7 @@ public:
/// Deleted blocks still have successor info, but their predecessor edges and
/// Phi nodes may already be updated. Instructions in DeadBlocks should be
/// deleted after this call.
- void removeBlocks(const SmallPtrSetImpl<BasicBlock *> &DeadBlocks);
+ void removeBlocks(const SmallSetVector<BasicBlock *, 8> &DeadBlocks);
/// Get handle on MemorySSA.
MemorySSA* getMemorySSA() const { return MSSA; }
diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp
index 6c817d20368..a6c7142a697 100644
--- a/llvm/lib/Analysis/MemorySSAUpdater.cpp
+++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp
@@ -1101,7 +1101,7 @@ void MemorySSAUpdater::removeMemoryAccess(MemoryAccess *MA) {
}
void MemorySSAUpdater::removeBlocks(
- const SmallPtrSetImpl<BasicBlock *> &DeadBlocks) {
+ const SmallSetVector<BasicBlock *, 8> &DeadBlocks) {
// First delete all uses of BB in MemoryPhis.
for (BasicBlock *BB : DeadBlocks) {
Instruction *TI = BB->getTerminator();
diff --git a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
index 2e5927f9a06..f464df26a02 100644
--- a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
@@ -388,8 +388,8 @@ private:
void deleteDeadLoopBlocks() {
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
if (MSSAU) {
- SmallPtrSet<BasicBlock *, 8> DeadLoopBlocksSet(DeadLoopBlocks.begin(),
- DeadLoopBlocks.end());
+ SmallSetVector<BasicBlock *, 8> DeadLoopBlocksSet(DeadLoopBlocks.begin(),
+ DeadLoopBlocks.end());
MSSAU->removeBlocks(DeadLoopBlocksSet);
}
for (auto *BB : DeadLoopBlocks) {
diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index 5a67178cef3..814cf814989 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -1436,8 +1436,8 @@ deleteDeadClonedBlocks(Loop &L, ArrayRef<BasicBlock *> ExitBlocks,
// Remove all MemorySSA in the dead blocks
if (MSSAU) {
- SmallPtrSet<BasicBlock *, 16> DeadBlockSet(DeadBlocks.begin(),
- DeadBlocks.end());
+ SmallSetVector<BasicBlock *, 8> DeadBlockSet(DeadBlocks.begin(),
+ DeadBlocks.end());
MSSAU->removeBlocks(DeadBlockSet);
}
@@ -1455,7 +1455,7 @@ static void deleteDeadBlocksFromLoop(Loop &L,
MemorySSAUpdater *MSSAU) {
// Find all the dead blocks tied to this loop, and remove them from their
// successors.
- SmallPtrSet<BasicBlock *, 16> DeadBlockSet;
+ SmallSetVector<BasicBlock *, 8> DeadBlockSet;
// Start with loop/exit blocks and get a transitive closure of reachable dead
// blocks.
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 499e611acb5..83dabcd7952 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -2211,7 +2211,7 @@ bool llvm::removeUnreachableBlocks(Function &F, LazyValueInfo *LVI,
assert(Reachable.size() < F.size());
NumRemoved += F.size()-Reachable.size();
- SmallPtrSet<BasicBlock *, 16> DeadBlockSet;
+ SmallSetVector<BasicBlock *, 8> DeadBlockSet;
for (Function::iterator I = ++F.begin(), E = F.end(); I != E; ++I) {
auto *BB = &*I;
if (Reachable.count(BB))
diff --git a/llvm/test/Analysis/MemorySSA/nondeterminism.ll b/llvm/test/Analysis/MemorySSA/nondeterminism.ll
new file mode 100644
index 00000000000..0bb3df30b58
--- /dev/null
+++ b/llvm/test/Analysis/MemorySSA/nondeterminism.ll
@@ -0,0 +1,122 @@
+; RUN: opt -simplifycfg -enable-mssa-loop-dependency -S --preserve-ll-uselistorder %s | FileCheck %s
+; REQUIRES: x86-registered-target
+; CHECK-LABEL: @n
+; CHECK: uselistorder i16 0, { 3, 2, 4, 1, 5, 0, 6 }
+
+; Note: test was added in an effort to ensure determinism when updating memoryssa. See PR42574.
+; If the uselistorder check becomes no longer relevant, the test can be disabled or removed.
+
+%rec9 = type { i16, i32, i32 }
+
+@a = global [1 x [1 x %rec9]] zeroinitializer
+
+define i16 @n() {
+ br label %..split_crit_edge
+
+..split_crit_edge: ; preds = %0
+ br label %.split
+
+bb4.us4: ; preds = %bb2.split.us32, %bb6.us28
+ %i.4.01.us5 = phi i16 [ %_tmp49.us30, %bb6.us28 ]
+ br label %g.exit4.us21
+
+bb1.i.us14: ; preds = %bb4.us4
+ br label %g.exit4.us21
+
+g.exit4.us21: ; preds = %bb1.i.us14, %g.exit4.critedge.us9
+ %i.4.02.us22 = phi i16 [ %i.4.01.us5, %bb4.us4 ], [ %i.4.01.us5, %bb1.i.us14 ]
+ br label %bb6.us28
+
+bb5.us26: ; preds = %g.exit4.us21
+ br label %bb6.us28
+
+bb6.us28: ; preds = %bb5.us26, %g.exit4.us21
+ %i.4.03.us29 = phi i16 [ %i.4.02.us22, %bb5.us26 ], [ %i.4.02.us22, %g.exit4.us21 ]
+ %_tmp49.us30 = add nuw nsw i16 %i.4.03.us29, 1
+ br label %bb4.us4
+
+bb4.us.us: ; preds = %bb2.split.us.us, %bb6.us.us
+ %i.4.01.us.us = phi i16 [ %_tmp49.us.us, %bb6.us.us ]
+ br label %bb1.i.us.us
+
+bb1.i.us.us: ; preds = %bb4.us.us
+ br label %g.exit4.us.us
+
+g.exit4.us.us: ; preds = %bb1.i.us.us, %g.exit4.critedge.us.us
+ %i.4.02.us.us = phi i16 [ %i.4.01.us.us, %bb1.i.us.us ]
+ br label %bb5.us.us
+
+bb5.us.us: ; preds = %g.exit4.us.us
+ br label %bb6.us.us
+
+bb6.us.us: ; preds = %bb5.us.us, %g.exit4.us.us
+ %i.4.03.us.us = phi i16 [ %i.4.02.us.us, %bb5.us.us ]
+ %_tmp49.us.us = add nuw nsw i16 %i.4.03.us.us, 1
+ br label %bb4.us.us
+
+
+.split: ; preds = %..split_crit_edge
+ br label %bb2
+
+bb2: ; preds = %.split, %bb7
+ %h.3.0 = phi i16 [ undef, %.split ], [ %_tmp53, %bb7 ]
+ br label %bb2.bb2.split_crit_edge
+
+bb2.bb2.split_crit_edge: ; preds = %bb2
+ br label %bb2.split
+
+bb2.split.us: ; preds = %bb2
+ br label %bb4.us
+
+bb4.us: ; preds = %bb6.us, %bb2.split.us
+ %i.4.01.us = phi i16 [ 0, %bb2.split.us ]
+ br label %bb1.i.us
+
+g.exit4.critedge.us: ; preds = %bb4.us
+ br label %g.exit4.us
+
+bb1.i.us: ; preds = %bb4.us
+ br label %g.exit4.us
+
+g.exit4.us: ; preds = %bb1.i.us, %g.exit4.critedge.us
+ %i.4.02.us = phi i16 [ %i.4.01.us, %g.exit4.critedge.us ], [ %i.4.01.us, %bb1.i.us ]
+ br label %bb5.us
+
+bb5.us: ; preds = %g.exit4.us
+ br label %bb7
+
+bb2.split: ; preds = %bb2.bb2.split_crit_edge
+ br label %bb4
+
+bb4: ; preds = %bb2.split, %bb6
+ %i.4.01 = phi i16 [ 0, %bb2.split ]
+ %_tmp16 = getelementptr [1 x [1 x %rec9]], [1 x [1 x %rec9]]* @a, i16 0, i16 %h.3.0, i16 %i.4.01, i32 0
+ %_tmp17 = load i16, i16* %_tmp16, align 1
+ br label %g.exit4.critedge
+
+bb1.i: ; preds = %bb4
+ br label %g.exit4
+
+g.exit4.critedge: ; preds = %bb4
+ %_tmp28.c = getelementptr [1 x [1 x %rec9]], [1 x [1 x %rec9]]* @a, i16 0, i16 %h.3.0, i16 %i.4.01, i32 1
+ %_tmp29.c = load i32, i32* %_tmp28.c, align 1
+ %_tmp30.c = trunc i32 %_tmp29.c to i16
+ br label %g.exit4
+
+g.exit4: ; preds = %g.exit4.critedge, %bb1.i
+ %i.4.02 = phi i16 [ %i.4.01, %g.exit4.critedge ], [ %i.4.01, %bb1.i ]
+ %_tmp41 = getelementptr [1 x [1 x %rec9]], [1 x [1 x %rec9]]* @a, i16 0, i16 %h.3.0, i16 %i.4.02, i32 2
+ br label %bb6
+
+bb5: ; preds = %g.exit4
+ br label %bb6
+
+bb6: ; preds = %bb5, %g.exit4
+ %i.4.03 = phi i16 [ %i.4.02, %bb5 ], [ %i.4.02, %g.exit4 ]
+ %_tmp49 = add nuw nsw i16 %i.4.03, 1
+ br label %bb7
+
+bb7: ; preds = %bb7.us-lcssa.us, %bb7.us-lcssa
+ %_tmp53 = add nsw i16 %h.3.0, 1
+ br label %bb2
+}
--
2.24.0
......@@ -10,11 +10,13 @@ export PATH="/var/tmp/dist/cmake/bin:$PATH"
[% pc('gcc', 'var/setup', { compiler_tarfile => c('input_files_by_name/gcc'),
hardened_gcc => 0 }) %]
ln -s gcc /var/tmp/dist/gcc/bin/cc
tar -C /var/tmp/dist -xf [% c('input_files_by_name/binutils') %]
export PATH="/var/tmp/dist/binutils/bin:$PATH"
[% END -%]
mkdir -p /var/tmp/build
cd /var/tmp/build
tar -xf $rootdir/[% c('input_files_by_name/llvm') %]
tar -xf $rootdir/[% c('input_files_by_name/cfe') %]
tar -xf $rootdir/[% c('input_files_by_name/clang') %]
tar -xf $rootdir/[% c('input_files_by_name/libcxx') %]
tar -xf $rootdir/[% c('input_files_by_name/libcxxabi') %]
tar -xf $rootdir/[% c('input_files_by_name/lld') %]
......@@ -22,26 +24,19 @@ tar -xf $rootdir/[% c('input_files_by_name/compiler-rt') %]
mv llvm-* llvm
# LLVM has reproducibility issues when optimizing bitcode, which we need to
# patch. See: #32053 for more details.
patch -p1 < $rootdir/42574.patch
patch -p1 < $rootdir/43909.patch
mv cfe-* llvm/tools/clang
mv clang-* llvm/tools/clang
mv libcxx-* llvm/projects/libcxx
mv libcxxabi-* llvm/projects/libcxxabi
mv lld-* llvm/tools/lld
mv compiler-rt-* llvm/projects/compiler-rt
[% IF c("var/windows") -%]
# Patch order is important here
for i in {1..12}
do git apply $rootdir/win-patches/llvm-objcopy-$i.patch
done
patch -p1 -d llvm/tools/lld < $rootdir/timestamp.patch
[% END %]
cd llvm
export LLVM_HOME=$(pwd)
mkdir build
cd build
cmake .. -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$distdir \
-DCMAKE_BUILD_TYPE:STRING=Release \
[% IF c("var/linux") -%]-DCOMPILER_RT_BUILD_CRT=OFF \[% END -%]
[% IF c("var/rlbox") -%]-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly \[% END -%]
$LLVM_HOME
make -j[% c("buildconf/num_procs") %]
......
# vim: filetype=yaml sw=2
version: 8.0.1
version: 9.0.1
filename: '[% project %]-[% c("version") %]-[% c("var/build_id") %].tar.gz'
gpg_keyring: clang.gpg
sig_ext: sig
......@@ -8,26 +8,21 @@ var:
container:
use_container: 1
targets:
windows:
var:
arch_deps:
# We use git to apply patches
- git
input_files:
- project: container-image
- name: '[% c("var/compiler") %]'
project: '[% c("var/compiler") %]'
enable: '[% c("var/linux") %]'
- name: binutils
project: binutils
enable: '[% c("var/linux") %]'
- project: cmake
name: cmake
- URL: 'https://github.com/llvm/llvm-project/releases/download/llvmorg-[% c("version") %]/llvm-[% c("version") %].src.tar.xz'
name: llvm
file_gpg_id: 1
- URL: 'https://github.com/llvm/llvm-project/releases/download/llvmorg-[% c("version") %]/cfe-[% c("version") %].src.tar.xz'
name: cfe
- URL: 'https://github.com/llvm/llvm-project/releases/download/llvmorg-[% c("version") %]/clang-[% c("version") %].src.tar.xz'
name: clang
file_gpg_id: 1
- URL: 'https://github.com/llvm/llvm-project/releases/download/llvmorg-[% c("version") %]/libcxx-[% c("version") %].src.tar.xz'
name: libcxx
......@@ -41,9 +36,4 @@ input_files:
- URL: 'https://github.com/llvm/llvm-project/releases/download/llvmorg-[% c("version") %]/compiler-rt-[% c("version") %].src.tar.xz'
name: compiler-rt
file_gpg_id: 1
- filename: win-patches
enable: '[% c("var/windows") %]'
- filename: timestamp.patch
enable: '[% c("var/windows") %]'
- filename: 42574.patch
- filename: 43909.patch
From f4743f40894d1dcd4ba131af3ad86a34c6d54598 Mon Sep 17 00:00:00 2001
From: Martin Storsjo <martin@martin.st>
Date: Tue, 5 Feb 2019 08:16:06 +0000
Subject: [PATCH] Hook up the --no-insert-timestamp option
This fixes PR40582.
Patch by Georg Koppen!
Differential Revision: https://reviews.llvm.org/D57679
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@353145 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/MinGW/Driver.cpp b/MinGW/Driver.cpp
index 27a5550ec..d79ebe82e 100644
--- a/MinGW/Driver.cpp
+++ b/MinGW/Driver.cpp
@@ -170,6 +170,9 @@ bool mingw::link(ArrayRef<const char *> ArgsArr, raw_ostream &Diag) {
Args.getLastArgValue(OPT_m) != "arm64pe" && !Args.hasArg(OPT_dynamicbase))
Add("-dynamicbase:no");
+ if (Args.hasArg(OPT_no_insert_timestamp))
+ Add("-timestamp:0");
+
if (Args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, false))
Add("-opt:ref");
else
diff --git a/MinGW/Options.td b/MinGW/Options.td
index ad699f711..5cc339a4a 100644
--- a/MinGW/Options.td
+++ b/MinGW/Options.td
@@ -20,6 +20,8 @@ def l: JoinedOrSeparate<["-"], "l">, MetaVarName<"<libName>">,
def m: JoinedOrSeparate<["-"], "m">, HelpText<"Set target emulation">;
def map: S<"Map">, HelpText<"Output a linker map">;
def map_eq: J<"Map=">, Alias<map>;
+def no_insert_timestamp: F<"no-insert-timestamp">,
+ HelpText<"Don't include PE header timestamp">;
def no_whole_archive: F<"no-whole-archive">,
HelpText<"No longer include all object files for following archives">;
def large_address_aware: Flag<["--"], "large-address-aware">,
diff --git a/test/MinGW/driver.test b/test/MinGW/driver.test
index 3222bb111..b853527a0 100644
--- a/test/MinGW/driver.test
+++ b/test/MinGW/driver.test
@@ -151,3 +151,6 @@ REQUIRE-DEFINED: -include:_foo -include:_bar -include:_baz -include:_foo2
RUN: ld.lld -### -m i386pep foo.o -Llibpath | FileCheck -check-prefix LIBPATH %s
LIBPATH: -libpath:libpath
+
+RUN: ld.lld -### -m i386pep foo.o --no-insert-timestamp | FileCheck -check-prefix NOTIMESTAMP %s
+NOTIMESTAMP: -timestamp:0
--
2.23.0.rc1
From a495c9ae6fb3367e6b59d8d245273ed3669754f0 Mon Sep 17 00:00:00 2001
From: Martin Storsjo <martin@martin.st>
Date: Sat, 19 Jan 2019 19:42:23 +0000
Subject: [PATCH] [llvm-objcopy] [COFF] Remove a superfluous namespace
qualification. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351658 91177308-0d34-0410-b5e6-96231b3b80d8
---
tools/llvm-objcopy/COFF/COFFObjcopy.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp b/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
index ceebf600b3a..437dccbd3d5 100644
--- a/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
+++ b/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
@@ -78,7 +78,7 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj) {
}
void executeObjcopyOnBinary(const CopyConfig &Config,
- object::COFFObjectFile &In, Buffer &Out) {
+ COFFObjectFile &In, Buffer &Out) {
COFFReader Reader(In);
Expected<std::unique_ptr<Object>> ObjOrErr = Reader.create();
if (!ObjOrErr)
--
2.17.1
From 1284ee3c47bab17ec081b5169633aea4f8abfd30 Mon Sep 17 00:00:00 2001
From: Martin Storsjo <martin@martin.st>
Date: Wed, 23 Jan 2019 09:12:53 +0000
Subject: [PATCH] [llvm-objcopy] [COFF] Clear the unwritten tail of
coff_section::Header::Name
This should fix the add-gnu-debuglink test on all buildbots.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351934 91177308-0d34-0410-b5e6-96231b3b80d8
---
tools/llvm-objcopy/COFF/Writer.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/tools/llvm-objcopy/COFF/Writer.cpp b/llvm/tools/llvm-objcopy/COFF/Writer.cpp
index 05e46291c39..db897e2ff33 100644
--- a/llvm/tools/llvm-objcopy/COFF/Writer.cpp
+++ b/llvm/tools/llvm-objcopy/COFF/Writer.cpp
@@ -121,6 +121,7 @@ size_t COFFWriter::finalizeStringTable() {
for (auto &S : Obj.getMutableSections()) {
if (S.Name.size() > COFF::NameSize) {
+ memset(S.Header.Name, 0, sizeof(S.Header.Name));
snprintf(S.Header.Name, sizeof(S.Header.Name), "/%d",
(int)StrTabBuilder.getOffset(S.Name));
} else {
--
2.17.1
From 74c7d422cba163635394ec32f2b243b1de502a18 Mon Sep 17 00:00:00 2001
From: Martin Storsjo <martin@martin.st>
Date: Wed, 23 Jan 2019 11:54:51 +0000
Subject: [PATCH] [llvm-objcopy] [COFF] Fix handling of aux symbols for big
objects
The aux symbols were stored in an opaque std::vector<uint8_t>,
with contents interpreted according to the rest of the symbol.
All aux symbol types but one fit in 18 bytes (sizeof(coff_symbol16)),
and if written to a bigobj, two extra padding bytes are written (as
sizeof(coff_symbol32) is 20). In the storage agnostic intermediate
representation, store the aux symbols as a series of coff_symbol16
sized opaque blobs. (In practice, all such aux symbols only consist
of one aux symbol, so this is more flexible than what reality needs.)
The special case is the file aux symbols, which are written in
potentially more than one aux symbol slot, without any padding,
as one single long string. This can't be stored in the same opaque
vector of fixed sized aux symbol entries. The file aux symbols will
occupy a different number of aux symbol slots depending on the type
of output object file. As nothing in the intermediate process needs
to have accurate raw symbol indices, updating that is moved into the
writer class.
Differential Revision: https://reviews.llvm.org/D57009
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351947 91177308-0d34-0410-b5e6-96231b3b80d8
---
.../llvm-objcopy/COFF/Inputs/bigobj.o.gz | Bin 0 -> 7841 bytes
test/tools/llvm-objcopy/COFF/bigobj.test | 35 +++++++++++++
.../llvm-objcopy/ELF/auto-remove-shndx.test | 2 +-
.../tools/llvm-objcopy/ELF/many-sections.test | 2 +-
test/tools/llvm-objcopy/ELF/remove-shndx.test | 2 +-
.../tools/llvm-objcopy/ELF/strict-no-add.test | 2 +-
.../llvm-objcopy/{ELF => }/Inputs/ungzip.py | 0
tools/llvm-objcopy/COFF/COFFObjcopy.cpp | 6 +--
tools/llvm-objcopy/COFF/Object.cpp | 6 +--
tools/llvm-objcopy/COFF/Object.h | 18 ++++++-
tools/llvm-objcopy/COFF/Reader.cpp | 21 ++++++--
tools/llvm-objcopy/COFF/Writer.cpp | 49 +++++++++++++-----
tools/llvm-objcopy/COFF/Writer.h | 2 +-
13 files changed, 115 insertions(+), 30 deletions(-)
create mode 100644 test/tools/llvm-objcopy/COFF/Inputs/bigobj.o.gz
create mode 100644 test/tools/llvm-objcopy/COFF/bigobj.test
rename test/tools/llvm-objcopy/{ELF => }/Inputs/ungzip.py (100%)
diff --git a/llvm/test/tools/llvm-objcopy/COFF/Inputs/bigobj.o.gz b/llvm/test/tools/llvm-objcopy/COFF/Inputs/bigobj.o.gz
new file mode 100644
index 0000000000000000000000000000000000000000..6435f4785ff76e0c6bca12f3e57bc6ad8888bece
GIT binary patch
literal 7841
zcmb2|=3r3v^@w3&etUMmo^zoH`-kGKM_vfJsF<z%6+Sz#g6qq)pf0Hj#_r`4B7DML
zW(h1l`+!x)t@&W-R@I~lyKmU3Ti&1Z=iKur;uBMy1MR!_ywlsouYY&-*4H1mU!Qw=
z`RpIDkw;!V4(WOF_)B3`(Vt|~S>?L-b)Wx@^wig`HIMAw|N8V<v65oeyETs611{)_
zm27RwTe)ENN|7SLgM~83N6}~qjE2By2#kinXb6mkz-S1JhQMeDjE2By2#kinXb6mk
zz-S1JhQMeDjE2By2#kinXb6mkz-S1JhQMeDjE2By2#kgRokHNw|D97mKRo|%+Z6Ym
z*X{Ku$4#4*Vqm}gyYR^b^Sc?_E*<<cFE#Q=*rt6OBmJeLZ=aoe_u9R>-w!^l5biDe
p{d@nvw*mU6<NG83=jxn4_wt_G?yUy#YeOF~KhH^=cj<;Y0{~9Br>p<~
literal 0
HcmV?d00001
diff --git a/llvm/test/tools/llvm-objcopy/COFF/bigobj.test b/llvm/test/tools/llvm-objcopy/COFF/bigobj.test
new file mode 100644
index 00000000000..17968f12b8a
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/COFF/bigobj.test
@@ -0,0 +1,35 @@
+RUN: %python %p/../Inputs/ungzip.py %p/Inputs/bigobj.o.gz > %t.in.o
+
+RUN: llvm-objdump -t %t.in.o | FileCheck %s --check-prefixes=SYMBOLS,SYMBOLS-BIG,SYMBOLS-ORIG
+
+# Do a plain copy, to check that section numbers in symbols referring
+# to sections outside of the small object format are handled correctly.
+RUN: llvm-objcopy -R '.text$4' %t.in.o %t.small.o
+RUN: llvm-objdump -t %t.in.o | FileCheck %s --check-prefixes=SYMBOLS,SYMBOLS-BIG,SYMBOLS-ORIG
+
+# Remove a section, making the section count fit into a small object.
+RUN: llvm-objcopy -R '.text$4' %t.in.o %t.small.o
+RUN: llvm-objdump -t %t.small.o | FileCheck %s --check-prefixes=SYMBOLS,SYMBOLS-SMALL,SYMBOLS-REMOVED-SMALL
+
+# Add a .gnu_debuglink section, forcing the object back to big format.
+RUN: llvm-objcopy --add-gnu-debuglink=%t.in.o %t.small.o %t.big.o
+ llvm-objdump -t %t.big.o | FileCheck %s --check-prefixes=SYMBOLS,SYMBOLS-BIG,SYMBOLS-REMOVED-BIG
+
+# In big object format, the .file symbol occupies one symbol table entry for
+# the auxillary data, but needs two entries in the small format, forcing the
+# raw symbol indices of later symbols to change.
+SYMBOLS: SYMBOL TABLE:
+SYMBOLS-NEXT: [ 0]{{.*}} (nx 1) {{.*}} .text
+SYMBOLS-NEXT: AUX scnlen
+SYMBOLS-SMALL-NEXT: [ 2]{{.*}} (nx 2) {{.*}} .file
+SYMBOLS-BIG-NEXT: [ 2]{{.*}} (nx 1) {{.*}} .file
+SYMBOLS-NEXT: AUX abcdefghijklmnopqrs
+SYMBOLS-SMALL-NEXT: [ 5]{{.*}} (nx 0) {{.*}} foo
+SYMBOLS-BIG-NEXT: [ 4]{{.*}} (nx 0) {{.*}} foo
+
+# Check that the section numbers outside of signed 16 bit int range
+# are represented properly. After removing one section, the section
+# numbers decrease.
+SYMBOLS-ORIG: [ 5](sec 65280){{.*}} symbol65280
+SYMBOLS-REMOVED-SMALL: [ 6](sec 65279){{.*}} symbol65280
+SYMBOLS-REMOVED-BIG: [ 5](sec 65279){{.*}} symbol65280
diff --git a/llvm/test/tools/llvm-objcopy/ELF/auto-remove-shndx.test b/llvm/test/tools/llvm-objcopy/ELF/auto-remove-shndx.test
index 5a23493fa94..8e6c788bf48 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/auto-remove-shndx.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/auto-remove-shndx.test
@@ -1,4 +1,4 @@
-# RUN: %python %p/Inputs/ungzip.py %p/Inputs/many-sections.o.gz > %t
+# RUN: %python %p/../Inputs/ungzip.py %p/Inputs/many-sections.o.gz > %t
# RUN: llvm-objcopy -R .text -R s0 -R s1 -R s2 -R s3 -R s4 -R s5 -R s6 %t %t2
# RUN: llvm-readobj --sections %t2 | FileCheck --check-prefix=SECS %s
diff --git a/llvm/test/tools/llvm-objcopy/ELF/many-sections.test b/llvm/test/tools/llvm-objcopy/ELF/many-sections.test
index 57239f32e4a..1dd41cfb10c 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/many-sections.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/many-sections.test
@@ -1,4 +1,4 @@
-RUN: %python %p/Inputs/ungzip.py %p/Inputs/many-sections.o.gz > %t
+RUN: %python %p/../Inputs/ungzip.py %p/Inputs/many-sections.o.gz > %t
RUN: llvm-objcopy %t %t2
RUN: llvm-readobj --file-headers %t2 | FileCheck --check-prefix=EHDR %s
RUN: llvm-readobj --sections %t2 | FileCheck --check-prefix=SECS %s
diff --git a/llvm/test/tools/llvm-objcopy/ELF/remove-shndx.test b/llvm/test/tools/llvm-objcopy/ELF/remove-shndx.test
index 6cc3a1a291f..53ca8e7f220 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/remove-shndx.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/remove-shndx.test
@@ -1,6 +1,6 @@
# This test checks to see that a .symtab_shndx section is added to any binary
# that needs it, even if the original was removed.
-RUN: %python %p/Inputs/ungzip.py %p/Inputs/many-sections.o.gz > %t
+RUN: %python %p/../Inputs/ungzip.py %p/Inputs/many-sections.o.gz > %t
RUN: llvm-objcopy -R .symtab_shndx %t %t2
RUN: llvm-readobj --sections %t2 | FileCheck %s
diff --git a/llvm/test/tools/llvm-objcopy/ELF/strict-no-add.test b/llvm/test/tools/llvm-objcopy/ELF/strict-no-add.test
index 4f24df31bf9..348ab7c4fbd 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/strict-no-add.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/strict-no-add.test
@@ -1,7 +1,7 @@
# This test makes sure that sections added at the end that don't have symbols
# defined in them don't trigger the creation of a large index table.
-RUN: %python %p/Inputs/ungzip.py %p/Inputs/many-sections.o.gz > %t.0
+RUN: %python %p/../Inputs/ungzip.py %p/Inputs/many-sections.o.gz > %t.0
RUN: cat %p/Inputs/alloc-symtab.o > %t
RUN: llvm-objcopy -R .text -R s0 -R s1 -R s2 -R s3 -R s4 -R s5 -R s6 %t.0 %t2
RUN: llvm-objcopy --add-section=.s0=%t --add-section=.s1=%t --add-section=.s2=%t %t2 %t2
diff --git a/llvm/test/tools/llvm-objcopy/ELF/Inputs/ungzip.py b/llvm/test/tools/llvm-objcopy/Inputs/ungzip.py
similarity index 100%
rename from llvm/test/tools/llvm-objcopy/ELF/Inputs/ungzip.py
rename to llvm/test/tools/llvm-objcopy/Inputs/ungzip.py
diff --git a/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp b/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
index 20adbe11e7a..64b4e79a4e0 100644
--- a/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
+++ b/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
@@ -37,7 +37,7 @@ static uint64_t getNextRVA(const Object &Obj) {
return 0;
const Section &Last = Obj.getSections().back();
return alignTo(Last.Header.VirtualAddress + Last.Header.VirtualSize,
- Obj.PeHeader.SectionAlignment);
+ Obj.IsPE ? Obj.PeHeader.SectionAlignment : 1);
}
static uint32_t getCRC32(StringRef Data) {
@@ -74,8 +74,8 @@ static void addGnuDebugLink(Object &Obj, StringRef DebugLinkFile) {
Sec.Name = ".gnu_debuglink";
Sec.Header.VirtualSize = Sec.getContents().size();
Sec.Header.VirtualAddress = StartRVA;
- Sec.Header.SizeOfRawData =
- alignTo(Sec.Header.VirtualSize, Obj.PeHeader.FileAlignment);
+ Sec.Header.SizeOfRawData = alignTo(Sec.Header.VirtualSize,
+ Obj.IsPE ? Obj.PeHeader.FileAlignment : 1);
// Sec.Header.PointerToRawData is filled in by the writer.
Sec.Header.PointerToRelocations = 0;
Sec.Header.PointerToLinenumbers = 0;
diff --git a/llvm/tools/llvm-objcopy/COFF/Object.cpp b/llvm/tools/llvm-objcopy/COFF/Object.cpp
index 8c382c1faef..0ad5a05a144 100644
--- a/llvm/tools/llvm-objcopy/COFF/Object.cpp
+++ b/llvm/tools/llvm-objcopy/COFF/Object.cpp
@@ -26,12 +26,8 @@ void Object::addSymbols(ArrayRef<Symbol> NewSymbols) {
void Object::updateSymbols() {