Skip to content

Commit

Permalink
Merged master:c9790d54f83 into amd-gfx:e7e884ea599
Browse files Browse the repository at this point in the history
Local branch amd-gfx e7e884e Merged master:7e58d0ded09 into amd-gfx:c20d9f185ac
Remote branch master c9790d5 [PowerPC] Remove extra instruction left by emitRLDICWhenLoweringJumpTables
  • Loading branch information
Sw authored and Sw committed Jun 9, 2020
2 parents e7e884e + c9790d5 commit 98a9624
Show file tree
Hide file tree
Showing 24 changed files with 340 additions and 40 deletions.
1 change: 1 addition & 0 deletions libc/src/string/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function(add_implementation name impl_name)
REJECT ${ADD_IMPL_REJECT}
)
add_entrypoint_object(${impl_name}
NAME ${name}
SRCS ${ADD_IMPL_SRCS}
HDRS ${ADD_IMPL_HDRS}
DEPENDS ${ADD_IMPL_DEPENDS}
Expand Down
15 changes: 13 additions & 2 deletions lld/MachO/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,20 @@ opt::InputArgList MachOOptTable::parse(ArrayRef<const char *> argv) {
}

static Optional<std::string> findLibrary(StringRef name) {
std::string stub = (llvm::Twine("lib") + name + ".tbd").str();
std::string shared = (llvm::Twine("lib") + name + ".dylib").str();
std::string archive = (llvm::Twine("lib") + name + ".a").str();
llvm::SmallString<260> location;

for (StringRef dir : config->searchPaths) {
for (StringRef library : {shared, archive}) {
for (StringRef library : {stub, shared, archive}) {
location = dir;
llvm::sys::path::append(location, library);
if (fs::exists(location))
return location.str().str();
}
}
return None;
return {};
}

static TargetInfo *createTargetInfo(opt::InputArgList &args) {
Expand Down Expand Up @@ -135,6 +136,16 @@ static void addFile(StringRef path) {
case file_magic::macho_dynamically_linked_shared_lib:
inputFiles.push_back(make<DylibFile>(mbref));
break;
case file_magic::tapi_file: {
llvm::Expected<std::unique_ptr<llvm::MachO::InterfaceFile>> result =
TextAPIReader::get(mbref);
if (!result)
return;

std::unique_ptr<llvm::MachO::InterfaceFile> interface{std::move(*result)};
inputFiles.push_back(make<DylibFile>(std::move(interface)));
break;
}
default:
error(path + ": unhandled file type");
}
Expand Down
19 changes: 19 additions & 0 deletions lld/MachO/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,25 @@ DylibFile::DylibFile(MemoryBufferRef mb, DylibFile *umbrella)
}
}

DylibFile::DylibFile(std::shared_ptr<llvm::MachO::InterfaceFile> interface,
DylibFile *umbrella)
: InputFile(DylibKind, MemoryBufferRef()) {
if (umbrella == nullptr)
umbrella = this;

dylibName = saver.save(interface->getInstallName());
// TODO(compnerd) filter out symbols based on the target platform
for (const auto symbol : interface->symbols())
if (symbol->getArchitectures().has(config->arch))
symbols.push_back(
symtab->addDylib(saver.save(symbol->getName()), umbrella));
// TODO(compnerd) properly represent the hierarchy of the documents as it is
// in theory possible to have re-exported dylibs from re-exported dylibs which
// should be parent'ed to the child.
for (auto document : interface->documents())
reexported.push_back(make<DylibFile>(document, umbrella));
}

DylibFile::DylibFile() : InputFile(DylibKind, MemoryBufferRef()) {}

DylibFile *DylibFile::createLibSystemMock() {
Expand Down
6 changes: 6 additions & 0 deletions lld/MachO/InputFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/Object/Archive.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/TextAPI/MachO/InterfaceFile.h"
#include "llvm/TextAPI/MachO/TextAPIReader.h"

#include <map>
#include <vector>
Expand Down Expand Up @@ -73,6 +75,9 @@ class ObjFile : public InputFile {
// .dylib file
class DylibFile : public InputFile {
public:
explicit DylibFile(std::shared_ptr<llvm::MachO::InterfaceFile> interface,
DylibFile *umbrella = nullptr);

// Mach-O dylibs can re-export other dylibs as sub-libraries, meaning that the
// symbols in those sub-libraries will be available under the umbrella
// library's namespace. Those sub-libraries can also have their own
Expand All @@ -81,6 +86,7 @@ class DylibFile : public InputFile {
// to the root. On the other hand, if a dylib is being directly loaded
// (through an -lfoo flag), then `umbrella` should be a nullptr.
explicit DylibFile(MemoryBufferRef mb, DylibFile *umbrella = nullptr);

static bool classof(const InputFile *f) { return f->kind() == DylibKind; }

// Do not use this constructor!! This is meant only for createLibSystemMock(),
Expand Down
4 changes: 2 additions & 2 deletions lld/MachO/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class LCLoadDylinker : public LoadCommand {
void Writer::scanRelocations() {
for (InputSection *isec : inputSections) {
for (Reloc &r : isec->relocs) {
if (auto *s = r.target.dyn_cast<Symbol *>()) {
if (auto *s = r.target.dyn_cast<lld::macho::Symbol *>()) {
if (isa<Undefined>(s))
error("undefined symbol " + s->getName() + ", referenced from " +
sys::path::filename(isec->file->getName()));
Expand Down Expand Up @@ -329,7 +329,7 @@ static DenseMap<const InputSection *, size_t> buildInputSectionPriorities() {
// TODO: Make sure this handles weak symbols correctly.
for (InputFile *file : inputFiles)
if (isa<ObjFile>(file) || isa<ArchiveFile>(file))
for (Symbol *sym : file->symbols)
for (lld::macho::Symbol *sym : file->symbols)
if (auto *d = dyn_cast<Defined>(sym))
addSym(*d);

Expand Down
42 changes: 42 additions & 0 deletions lld/test/MachO/Inputs/MacOSX.sdk/usr/lib/libSystem.tbd
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--- !tapi-tbd-v3
archs: [ x86_64 ]
uuids: [ 'x86_64: 00000000-0000-0000-0000-000000000000' ]
platform: macosx
install-name: '/usr/lib/libSystem.B.dylib'
current-version: 0001.001.1
exports:
- archs: [ 'x86_64' ]
re-exports: [ '/usr/lib/system/libdyld.dylib',
'/usr/lib/system/libsystem_c.dylib',
'/usr/lib/system/libsystem_m.dylib' ]
--- !tapi-tbd-v3
archs: [ x86_64 ]
uuids: [ 'x86_64: 00000000-0000-0000-0000-000000000001' ]
platform: macosx
install-name: '/usr/lib/libdyld.dylib'
current-version: 0001.001.1
parent-umbrella: System
exports:
- archs: [ 'x86_64' ]
symbols: [ dyld_stub_binder ]
--- !tapi-tbd-v3
archs: [ x86_64 ]
uuids: [ 'x86_64: 00000000-0000-0000-0000-000000000002' ]
platform: macosx
install-name: '/usr/lib/libsystem_c.dylib'
current-version: 0001.001.1
parent-umbrella: System
exports:
- archs: [ 'x86_64' ]
symbols: [ ]
--- !tapi-tbd-v3
archs: [ x86_64 ]
uuids: [ 'x86_64: 00000000-0000-0000-0000-000000000003' ]
platform: macosx
install-name: '/usr/lib/libsystem_m.dylib'
current-version: 0001.001.1
parent-umbrella: System
exports:
- archs: [ 'x86_64' ]
symbols: [ ___nan ]
...
23 changes: 23 additions & 0 deletions lld/test/MachO/Inputs/iPhoneSimulator.sdk/usr/lib/libSystem.tbd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--- !tapi-tbd-v3
archs: [ i386, x86_64 ]
uuids: [ 'i386: 00000000-0000-0000-0000-000000000000', 'x86_64: 00000000-0000-0000-0000-000000000001' ]
platform: ios
install-name: '/usr/lib/libSystem.B.dylib'
current-version: 1281
exports:
- archs: [ i386, x86_64 ]
re-exports: [ '/usr/lib/system/libcache.dylib' ]
symbols: [ __crashreporter_info__ ]
--- !tapi-tbd-v3
archs: [ i386, x86_64 ]
uuids: [ 'i386: 00000000-0000-0000-0000-000000000002', 'x86_64: 00000000-0000-0000-0000-000000000003' ]
platform: ios
install-name: '/usr/lib/libcache.dylib'
current-version: 83
parent-umbrella: System
exports:
- archs: [ i386 ]
symbols: [ __cache_handle_memory_pressure_event ]
- archs: [ i386, x86_64 ]
symbols: [ _cache_create, _cache_destroy, _cache_get ]
...
15 changes: 15 additions & 0 deletions lld/test/MachO/invalid/stub-link.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# REQUIRES: x86

# RUN: mkdir -p %t
#
# RUN: llvm-mc -filetype obj -triple x86_64-apple-ios %s -o %t/test.o
# RUN: not lld -flavor darwinnew -o %t/test -Z -L%S/../Inputs/iPhoneSimulator.sdk/usr/lib -lSystem %t/test.o 2>&1 | FileCheck %s

# CHECK: error: undefined symbol __cache_handle_memory_pressure_event

.section __TEXT,__text
.global _main

_main:
movq __cache_handle_memory_pressure_event@GOTPCREL(%rip), %rax
ret
21 changes: 21 additions & 0 deletions lld/test/MachO/stub-link.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# REQUIRES: x86

# RUN: mkdir -p %t
#
# RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %s -o %t/test.o
# RUN: lld -flavor darwinnew -o %t/test -Z -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem %t/test.o
#
# RUN: llvm-objdump --bind --no-show-raw-insn -d -r %t/test | FileCheck %s

# CHECK: Disassembly of section __TEXT,__text:
# CHECK: movq {{.*}} # [[ADDR:[0-9a-f]+]]

# CHECK: Bind table:
# CHECK: __DATA_CONST __got 0x[[ADDR]] pointer 0 libSystem ___nan

.section __TEXT,__text
.global _main

_main:
movq ___nan@GOTPCREL(%rip), %rax
ret
6 changes: 6 additions & 0 deletions llvm/CODE_OWNERS.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ beautification by scripts. The fields are: name (N), email (E), web-address
(S) and (I) IRC handle. Each entry should contain at least the (N), (E) and
(D) fields.

N: Matt Arsenault
E: Matthew.Arsenault@amd.com
E: arsenm2@gmail.com
I: arsenm
D: InferAddressSpaces

N: Simon Atanasyan
E: simon@atanasyan.com
D: MIPS Backend (lib/Target/Mips/*)
Expand Down
22 changes: 15 additions & 7 deletions llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,11 +970,15 @@ class AArch64Operand : public MCParsedAsmOperand {
bool isMOVZMovAlias() const {
if (!isImm()) return false;

const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
if (!CE) return false;
uint64_t Value = CE->getValue();
const MCExpr *E = getImm();
if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(E)) {
uint64_t Value = CE->getValue();

return AArch64_AM::isMOVZMovAlias(Value, Shift, RegWidth);
return AArch64_AM::isMOVZMovAlias(Value, Shift, RegWidth);
}
// Only supports the case of Shift being 0 if an expression is used as an
// operand
return !Shift && E;
}

template<int RegWidth, int Shift>
Expand Down Expand Up @@ -1774,9 +1778,13 @@ class AArch64Operand : public MCParsedAsmOperand {
void addMOVZMovAliasOperands(MCInst &Inst, unsigned N) const {
assert(N == 1 && "Invalid number of operands!");

const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
uint64_t Value = CE->getValue();
Inst.addOperand(MCOperand::createImm((Value >> Shift) & 0xffff));
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
if (CE) {
uint64_t Value = CE->getValue();
Inst.addOperand(MCOperand::createImm((Value >> Shift) & 0xffff));
} else {
addExpr(Inst, getImm());
}
}

template<int Shift>
Expand Down
26 changes: 19 additions & 7 deletions llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,22 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target,
static_cast<AArch64MCExpr::VariantKind>(Target.getRefKind());
if (AArch64MCExpr::getSymbolLoc(RefKind) != AArch64MCExpr::VK_ABS &&
AArch64MCExpr::getSymbolLoc(RefKind) != AArch64MCExpr::VK_SABS) {
// VK_GOTTPREL, VK_TPREL, VK_DTPREL are movw fixups, but they can't
// ever be resolved in the assembler.
Ctx.reportError(Fixup.getLoc(),
"relocation for a thread-local variable points to an "
"absolute symbol");
if (!RefKind) {
// The fixup is an expression
if (SignedValue > 0xFFFF || SignedValue < -0xFFFF)
Ctx.reportError(Fixup.getLoc(),
"fixup value out of range [-0xFFFF, 0xFFFF]");

// Invert the negative immediate because it will feed into a MOVN.
if (SignedValue < 0)
SignedValue = ~SignedValue;
Value = static_cast<uint64_t>(SignedValue);
} else
// VK_GOTTPREL, VK_TPREL, VK_DTPREL are movw fixups, but they can't
// ever be resolved in the assembler.
Ctx.reportError(Fixup.getLoc(),
"relocation for a thread-local variable points to an "
"absolute symbol");
return Value;
}

Expand Down Expand Up @@ -440,8 +451,9 @@ void AArch64AsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
// FIXME: getFixupKindInfo() and getFixupKindNumBytes() could be fixed to
// handle this more cleanly. This may affect the output of -show-mc-encoding.
AArch64MCExpr::VariantKind RefKind =
static_cast<AArch64MCExpr::VariantKind>(Target.getRefKind());
if (AArch64MCExpr::getSymbolLoc(RefKind) == AArch64MCExpr::VK_SABS) {
static_cast<AArch64MCExpr::VariantKind>(Target.getRefKind());
if (AArch64MCExpr::getSymbolLoc(RefKind) == AArch64MCExpr::VK_SABS ||
(!RefKind && Fixup.getTargetKind() == AArch64::fixup_aarch64_movw)) {
// If the immediate is negative, generate MOVN else MOVZ.
// (Bit 30 = 0) ==> MOVN, (Bit 30 = 1) ==> MOVZ.
if (SignedValue < 0)
Expand Down
31 changes: 16 additions & 15 deletions llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,23 +569,24 @@ unsigned AArch64MCCodeEmitter::fixMOVZ(const MCInst &MI, unsigned EncodedValue,
if (UImm16MO.isImm())
return EncodedValue;

const AArch64MCExpr *A64E = cast<AArch64MCExpr>(UImm16MO.getExpr());
switch (A64E->getKind()) {
case AArch64MCExpr::VK_DTPREL_G2:
case AArch64MCExpr::VK_DTPREL_G1:
case AArch64MCExpr::VK_DTPREL_G0:
case AArch64MCExpr::VK_GOTTPREL_G1:
case AArch64MCExpr::VK_TPREL_G2:
case AArch64MCExpr::VK_TPREL_G1:
case AArch64MCExpr::VK_TPREL_G0:
return EncodedValue & ~(1u << 30);
default:
// Nothing to do for an unsigned fixup.
return EncodedValue;
const MCExpr *E = UImm16MO.getExpr();
if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(E)) {
switch (A64E->getKind()) {
case AArch64MCExpr::VK_DTPREL_G2:
case AArch64MCExpr::VK_DTPREL_G1:
case AArch64MCExpr::VK_DTPREL_G0:
case AArch64MCExpr::VK_GOTTPREL_G1:
case AArch64MCExpr::VK_TPREL_G2:
case AArch64MCExpr::VK_TPREL_G1:
case AArch64MCExpr::VK_TPREL_G0:
return EncodedValue & ~(1u << 30);
default:
// Nothing to do for an unsigned fixup.
return EncodedValue;
}
}


return EncodedValue & ~(1u << 30);
return EncodedValue;
}

void AArch64MCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS,
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,9 @@ bool AMDGPUSimplifyLibCalls::runOnFunction(Function &F) {
// Ignore non-calls.
CallInst *CI = dyn_cast<CallInst>(I);
++I;
if (!CI) continue;
// Ignore intrinsics that do not become real instructions.
if (!CI || isa<DbgInfoIntrinsic>(CI) || CI->isLifetimeStartOrEnd())
continue;

// Ignore indirect calls.
Function *Callee = CI->getCalledFunction();
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ PPCMCCodeEmitter::getImm34Encoding(const MCInst &MI, unsigned OpNo,
return getMachineOpValue(MI, MO, Fixups, STI);

// Add a fixup for the immediate field.
Fixups.push_back(MCFixup::create(IsLittleEndian? 0 : 1, MO.getExpr(),
Fixups.push_back(MCFixup::create(0, MO.getExpr(),
(MCFixupKind)PPC::fixup_ppc_pcrel34));
return 0;
}
Expand Down Expand Up @@ -217,7 +217,7 @@ PPCMCCodeEmitter::getMemRI34PCRelEncoding(const MCInst &MI, unsigned OpNo,
"VariantKind must be VK_PCREL or VK_PPC_GOT_PCREL");
// Generate the fixup for the relocation.
Fixups.push_back(
MCFixup::create(IsLittleEndian ? 0 : 1, Expr,
MCFixup::create(0, Expr,
static_cast<MCFixupKind>(PPC::fixup_ppc_pcrel34)));
// There is no offset to return so just return 0.
return 0;
Expand Down Expand Up @@ -249,7 +249,7 @@ PPCMCCodeEmitter::getMemRI34PCRelEncoding(const MCInst &MI, unsigned OpNo,
"VariantKind must be VK_PCREL or VK_PPC_GOT_PCREL");
// Generate the fixup for the relocation.
Fixups.push_back(
MCFixup::create(IsLittleEndian ? 0 : 1, Expr,
MCFixup::create(0, Expr,
static_cast<MCFixupKind>(PPC::fixup_ppc_pcrel34)));
assert(isInt<34>(CE->getValue()) && "Value must fit in 34 bits.");
// Return the offset that should be added to the relocation by the linker.
Expand Down
Loading

0 comments on commit 98a9624

Please sign in to comment.