diff --git a/.github/actions/build-test-all/action.yml b/.github/actions/build-test-all/action.yml index 15f7721f1564..e5ebc3e0c100 100644 --- a/.github/actions/build-test-all/action.yml +++ b/.github/actions/build-test-all/action.yml @@ -59,7 +59,7 @@ runs: -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/$INSTALL_PATH \ -DLLVM_TARGETS_TO_BUILD=$TARGETS \ -DLLVM_DEFAULT_TARGET_TRIPLE=$DEFAULT_TARGET \ - -DLLVM_ENABLE_PROJECTS="clang" \ + -DLLVM_ENABLE_PROJECTS="clang;lld" \ -DCLANG_ENABLE_ARCMT=false \ -DCLANG_ENABLE_STATIC_ANALYZER=false \ -DCLANG_BUILD_EXAMPLES=false \ @@ -75,11 +75,19 @@ runs: -DLLVM_BUILD_INSTRUMENTED_COVERAGE=false \ -DLLVM_INSTALL_UTILS=false \ -DLLVM_ENABLE_ASSERTIONS=$ENABLE_ASSERTIONS + - name: LLD Tests + if: inputs.enable-tests == 'true' + uses: ./.github/actions/build-test + with: + targets: FileCheck count llc llvm-as llvm-bcanalyzer llvm-config llvm-cvtres llvm-dis llvm-dwarfdump llvm-lib llvm-lipo llvm-mc llvm-nm llvm-objdump llvm-pdbutil llvm-readelf llvm-strip llvm-symbolizer not obj2yaml opt split-file yaml2obj lld + path: ${{env.LLD_PATH}}/test + working-dir: ${{env.BUILD_PATH}} + include: ${{inputs.include-only}} - name: LLVM Unit Tests if: inputs.enable-tests == 'true' uses: ./.github/actions/build-test with: - targets: UnitTests FileCheck count not lli llvm-strip llvm-install-name-tool dsymutil lli-child-target llvm-as llvm-bcanalyzer llvm-config llvm-cov llvm-cxxdump llvm-cvtres llvm-diff llvm-dis llvm-dwarfdump llvm-exegesis llvm-extract llvm-isel-fuzzer llvm-ifs llvm-jitlink llvm-opt-fuzzer llvm-lib llvm-link llvm-lto llvm-lto2 llvm-mc llvm-mca llvm-modextract llvm-nm llvm-objdump llvm-pdbutil llvm-profdata llvm-ranlib llvm-rc llvm-readelf llvm-rtdyld llvm-size llvm-split llvm-strings llvm-undname llvm-c-test llvm-cxxfilt llvm-xray yaml2obj obj2yaml yaml-bench verify-uselistorder bugpoint llc llvm-symbolizer opt sancov sanstats llvm-addr2line + targets: UnitTests lli llvm-install-name-tool dsymutil lli-child-target llvm-cov llvm-cxxdump llvm-diff llvm-exegesis llvm-extract llvm-isel-fuzzer llvm-ifs llvm-jitlink llvm-opt-fuzzer llvm-link llvm-lto llvm-lto2 llvm-mca llvm-modextract llvm-profdata llvm-ranlib llvm-rc llvm-rtdyld llvm-size llvm-split llvm-strings llvm-undname llvm-c-test llvm-cxxfilt llvm-xray yaml-bench verify-uselistorder bugpoint sancov sanstats llvm-addr2line path: ${{env.LLVM_PATH}}/test working-dir: ${{env.BUILD_PATH}} include: LLVM-Unit.*(${{inputs.include-only}}) @@ -211,4 +219,4 @@ runs: run: | cmake $GITHUB_WORKSPACE/$BENCH_PATH -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/$BENCH_PATH/cmake/patmos-clang-toolchain.cmake -DENABLE_TESTING=true make $J - ctest $J + ctest $J \ No newline at end of file diff --git a/.github/workflows/patmos-ci.yml b/.github/workflows/patmos-ci.yml index 5540a827ff78..31c147743a30 100644 --- a/.github/workflows/patmos-ci.yml +++ b/.github/workflows/patmos-ci.yml @@ -24,6 +24,7 @@ env: NEWLIB_BUILD_PATH: build-newlib BENCH_PATH: patmos-benchmarks BENCH_BUILD_PATH: build-bench + LLD_PATH: lld jobs: test-non-patmos: @@ -61,20 +62,16 @@ jobs: - platform: ubuntu-18.04 cc: gcc-9 cxx: g++-9 - gold_link: https://github.com/t-crest/patmos-gold/releases/download/v1.0.0-rc-1/patmos-gold-v1.0.0-rc-1.tar.gz simulator_link: https://github.com/t-crest/patmos-simulator/releases/download/1.0.2/patmos-simulator-x86_64-linux-gnu.tar.gz - platform: macOS-10.15 cc: clang cxx: clang++ - gold_link: https://github.com/t-crest/patmos-gold/releases/download/v1.0.0-rc-1/patmos-gold-x86_64-apple-darwin17.7.0.tar.gz simulator_link: https://github.com/t-crest/patmos-simulator/releases/download/1.0.2/patmos-simulator-x86_64-apple-darwin17.7.0.tar.gz env: - GOLD_TAR: patmos-gold.tar.gz SIMULAROT_TAR: patmos-simulator.tar.gz CC: ${{matrix.cc}} CXX: ${{matrix.cxx}} - GOLD_LINK: ${{matrix.gold_link}} SIMULATOR_LINK: ${{matrix.simulator_link}} steps: @@ -90,10 +87,8 @@ jobs: mkdir -p $INSTALL_PATH cd $INSTALL_PATH # Dowload Dependencies - wget -O $GOLD_TAR $GOLD_LINK wget -O $SIMULAROT_TAR $SIMULATOR_LINK # Extract dependencies - tar -xvf $GOLD_TAR tar -xvf $SIMULAROT_TAR # Set path echo "$GITHUB_WORKSPACE/$INSTALL_PATH/bin" >> $GITHUB_PATH diff --git a/README-Patmos.MD b/README-Patmos.MD index 63e081669086..66bcf3e29679 100644 --- a/README-Patmos.MD +++ b/README-Patmos.MD @@ -16,7 +16,6 @@ tar -xvf This will correctly install all artifacts into the right paths. You are now ready to use the compiler. Remember to set your `PATH` to point to `t-crest/local/bin`. -Also remember that you need [the Patmos Gold Linker](https://github.com/t-crest/patmos-gold) to be installed alongside the compiler. # Development @@ -50,7 +49,7 @@ The following commands with clone only the parts of the Patmos LLVM repository t ``` git clone --filter=blob:none --sparse git@github.com:t-crest/patmos-llvm-project cd patmos-llvm-project -git sparse-checkout add /.github /llvm /clang /compiler-rt +git sparse-checkout add /.github /llvm /clang /compiler-rt /lld /libunwind ``` ### Build @@ -64,7 +63,7 @@ In this folder, you must setup the build with `cmake` (referencing the LLVM subf ``` mkdir -p build cd build -cmake ../llvm -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD="Patmos" -DLLVM_DEFAULT_TARGET_TRIPLE=patmos-unknown-unknown-elf -DLLVM_ENABLE_PROJECTS="clang" -DCLANG_ENABLE_ARCMT=false -DCLANG_ENABLE_STATIC_ANALYZER=false -DCLANG_BUILD_EXAMPLES=false -DLLVM_ENABLE_BINDINGS=false -DLLVM_INSTALL_BINUTILS_SYMLINKS=false -DLLVM_INSTALL_CCTOOLS_SYMLINKS=false -DLLVM_INCLUDE_EXAMPLES=false -DLLVM_INCLUDE_BENCHMARKS=false -DLLVM_APPEND_VC_REV=false -DLLVM_ENABLE_WARNINGS=false -DLLVM_ENABLE_PEDANTIC=false -DLLVM_ENABLE_LIBPFM=false -DLLVM_BUILD_INSTRUMENTED_COVERAGE=false -DLLVM_INSTALL_UTILS=false +cmake ../llvm -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD="Patmos" -DLLVM_DEFAULT_TARGET_TRIPLE=patmos-unknown-unknown-elf -DLLVM_ENABLE_PROJECTS="clang;lld" -DCLANG_ENABLE_ARCMT=false -DCLANG_ENABLE_STATIC_ANALYZER=false -DCLANG_BUILD_EXAMPLES=false -DLLVM_ENABLE_BINDINGS=false -DLLVM_INSTALL_BINUTILS_SYMLINKS=false -DLLVM_INSTALL_CCTOOLS_SYMLINKS=false -DLLVM_INCLUDE_EXAMPLES=false -DLLVM_INCLUDE_BENCHMARKS=false -DLLVM_APPEND_VC_REV=false -DLLVM_ENABLE_WARNINGS=false -DLLVM_ENABLE_PEDANTIC=false -DLLVM_ENABLE_LIBPFM=false -DLLVM_BUILD_INSTRUMENTED_COVERAGE=false -DLLVM_INSTALL_UTILS=false make -j ``` @@ -105,6 +104,12 @@ To test Clang: make -j ClangPatmosTestDeps && ./bin/llvm-lit ../clang/test -v --filter=Patmos ``` +To test LLD (from the `build` folder): + +``` +make -j lld && ./bin/llvm-lit ../lld/test -v --filter=Patmos +``` + To test Compiler-RT, go to the `build-compiler-rt` folder: ``` diff --git a/clang/lib/Driver/ToolChains/Patmos.cpp b/clang/lib/Driver/ToolChains/Patmos.cpp index e124f35bcf31..35f54c49367c 100644 --- a/clang/lib/Driver/ToolChains/Patmos.cpp +++ b/clang/lib/Driver/ToolChains/Patmos.cpp @@ -463,7 +463,7 @@ void patmos::PatmosBaseTool::ConstructLLCJob(const Tool &Creator, LLCExec, LLCArgs, Inputs, Output)); } -static std::string get_patmos_gold(const ToolChain &TC, DiagnosticsEngine &Diag) +static std::string get_patmos_lld(const ToolChain &TC, DiagnosticsEngine &Diag) { char *gold_envvar = getenv("PATMOS_GOLD"); if (gold_envvar && strcmp(gold_envvar,"")!=0 ) { @@ -478,21 +478,13 @@ static std::string get_patmos_gold(const ToolChain &TC, DiagnosticsEngine &Diag) } } - auto tmp = TC.GetProgramPath("patmos-ld"); - if (tmp != "patmos-ld") { - return tmp; - }else{ - auto DiagID = Diag.getCustomDiagID(DiagnosticsEngine::Error, - "gold linker 'patmos-ld' not found"); - Diag.Report(DiagID); - return ""; - } + return(get_patmos_tool(TC, "ld.lld")); } -void patmos::PatmosBaseTool::ConstructGoldJob(const Tool &Creator, +void patmos::PatmosBaseTool::ConstructLLDJob(const Tool &Creator, Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, - const char *OutputFilename, const ArgStringList &GoldInputs, + const char *OutputFilename, const ArgStringList &LLDInputs, const ArgList &Args, bool AddStackSymbols) const { ArgStringList LDArgs; @@ -505,6 +497,8 @@ void patmos::PatmosBaseTool::ConstructGoldJob(const Tool &Creator, LDArgs.push_back("-nostdlib"); LDArgs.push_back("-static"); + // String merging seems to also change data saved as floats or doubles. Disable it to avoid the unwanted changes. + LDArgs.push_back("-O0"); LDArgs.push_back("--defsym"); LDArgs.push_back("__heap_start=end"); @@ -541,9 +535,9 @@ void patmos::PatmosBaseTool::ConstructGoldJob(const Tool &Creator, //---------------------------------------------------------------------------- // append all linker input arguments and construct the link command - LDArgs.append(GoldInputs.begin(), GoldInputs.end()); + LDArgs.append(LLDInputs.begin(), LLDInputs.end()); - const char *LDExec = Args.MakeArgString(get_patmos_gold(TC, C.getDriver().getDiags())); + const char *LDExec = Args.MakeArgString(get_patmos_lld(TC, C.getDriver().getDiags())); C.addCommand(std::make_unique( JA, Creator, ResponseFileSupport::AtFileCurCP(), LDExec, LDArgs, Inputs, Output)); @@ -648,10 +642,10 @@ void patmos::FinalLink::ConstructJob(Compilation &C, const JobAction &JA, ConstructLLCJob(*this, C, JA, Output, Inputs, llcOut, link4Out, Args); - ArgStringList GoldInputs; - GoldInputs.push_back(llcOut); - ConstructGoldJob(*this, C, JA, Output, Inputs, Output.getFilename(), - GoldInputs, Args, true); + ArgStringList LLDInputs; + LLDInputs.push_back(llcOut); + ConstructLLDJob(*this, C, JA, Output, Inputs, Output.getFilename(), + LLDInputs, Args, true); } diff --git a/clang/lib/Driver/ToolChains/Patmos.h b/clang/lib/Driver/ToolChains/Patmos.h index 56e623c00ad8..44cd3f9a0afd 100644 --- a/clang/lib/Driver/ToolChains/Patmos.h +++ b/clang/lib/Driver/ToolChains/Patmos.h @@ -104,12 +104,12 @@ class PatmosBaseTool { const char *InputFilename, const llvm::opt::ArgList &TCArgs) const; - void ConstructGoldJob(const Tool &Creator, Compilation &C, + void ConstructLLDJob(const Tool &Creator, Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const char *OutputFilename, - const llvm::opt::ArgStringList &GoldInputs, + const llvm::opt::ArgStringList &LLDInputs, const llvm::opt::ArgList &TCArgs, bool AddStackSymbols) const; }; diff --git a/clang/test/Driver/Patmos/default-patmos-gold.c b/clang/test/Driver/Patmos/default-patmos-gold.c deleted file mode 100644 index 864c5d505cef..000000000000 --- a/clang/test/Driver/Patmos/default-patmos-gold.c +++ /dev/null @@ -1,14 +0,0 @@ -// RUN: %clang --target=patmos %s -o %t -Wl,--bogus-patmos-gold-flag 2>&1 | \ -// RUN: FileCheck %s -// END. -/////////////////////////////////////////////////////////////////////////////////////////////////// -// -// Tests that patmos gold is searched for on the path by default. -// We test this by providing an illegal flag to it, and ensuring it fails with a message identifying -// as 'patmos-ld' -// -/////////////////////////////////////////////////////////////////////////////////////////////////// -int main() { } - -// CHECK: patmos-ld: --bogus-patmos-gold-flag: unknown option -// CHECK: error: Link final executable command failed \ No newline at end of file diff --git a/compiler-rt/test/builtins/Unit/patmos/lit.local.cfg b/compiler-rt/test/builtins/Unit/patmos/lit.local.cfg index 0991fc40d6fb..730286f1adb6 100644 --- a/compiler-rt/test/builtins/Unit/patmos/lit.local.cfg +++ b/compiler-rt/test/builtins/Unit/patmos/lit.local.cfg @@ -13,7 +13,7 @@ patmos_librt_path = config.compiler_rt_obj_root + "/lib/generic/libclang_rt.buil compile_to_bc = config.clang + " -O2 -c -emit-llvm %s -o %t_bc" link_with_librt_and_start = llvm_link_path + " --suppress-warnings %t_bc " + start_file_path + " " + patmos_librt_path + " -o %t_bc_linked" compile_to_obj = llc_path + " %t_bc_linked -filetype=obj -O0 -o %t_obj" -final_link = "patmos-ld -nostdlib -static %t_obj -o %t_exec" +final_link = "ld.lld --nostdlib --static %t_obj -o %t_exec" run_pasim = "pasim %t_exec" config.substitutions.append(("%test-patmos-librt", diff --git a/lld/ELF/Arch/Patmos.cpp b/lld/ELF/Arch/Patmos.cpp new file mode 100644 index 000000000000..621111eb3824 --- /dev/null +++ b/lld/ELF/Arch/Patmos.cpp @@ -0,0 +1,189 @@ +//===- Patmos.cpp ----------------------------------------------------------===// +// +// Addaption of File lld/ELF/Arch/RISCV.cpp 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 +// +//===----------------------------------------------------------------------===// + +#include "InputFiles.h" +#include "Symbols.h" +#include "SyntheticSections.h" +#include "Target.h" + +using namespace llvm; +using namespace llvm::object; +using namespace llvm::support::endian; +using namespace llvm::ELF; +using namespace lld; +using namespace lld::elf; + +namespace { + +class Patmos final : public TargetInfo { +public: + Patmos(); + RelExpr getRelExpr(RelType type, const Symbol &s, + const uint8_t *loc) const override; + void relocate(uint8_t *loc, const Relocation &rel, + uint64_t val) const override; +}; + +} + +Patmos::Patmos() { + defaultImageBase = 0x00020000; + + defaultMaxPageSize = 0x1000; + defaultCommonPageSize = 0x1000; +} + +// getRelExpr - decide what value is needed depending on the relocation type (absolute or relative) +//// @param loc Location Pointer to data/instruction the patching is needed +//// @param s Symbol +//// @param type What Relocation Type needed to be applied +RelExpr Patmos::getRelExpr(const RelType type, const Symbol &s, + const uint8_t *loc) const { + + // get which Relocation Value is returned + switch (type) { + case R_PATMOS_NONE: + return R_NONE; + case R_PATMOS_CFLI_ABS: + return R_ABS; // Absolute Address + case R_PATMOS_ALUI_ABS: + return R_ABS; + case R_PATMOS_ALUL_ABS: + return R_ABS; + case R_PATMOS_MEMB_ABS: + return R_ABS; + case R_PATMOS_MEMH_ABS: + return R_ABS; + case R_PATMOS_MEMW_ABS: + return R_ABS; + case R_PATMOS_ABS_32: + return R_ABS; + case R_PATMOS_CFLI_PCREL: + return R_PC; // Relative Address + default: + error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) + + ") against symbol " + toString(s)); + return R_NONE; + } +} + +// Extract bits V[Begin:End], where range is inclusive, and Begin must be < 63. +static uint32_t extractBits(uint64_t v, uint32_t begin, uint32_t end) { + return (v & ((1ULL << (begin + 1)) - 1)) >> end; +} + + +// relocate - patch data/instruction depending on the relocation type +//// @param loc Location Pointer to data/instruction where patching is needed +//// @param rel Relocation Type to be applied +//// @param val Value to be patched to the data/instruction +void Patmos::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const { + // Relocate Types defined in /llvm/include/llvm/BinaryFormat/ELF.h + + switch (rel.type) { + case R_PATMOS_CFLI_ABS: { + // Relocate CFLi format (22 bit immediate), absolute (unsigned), in words + checkUInt(loc, static_cast(val) >> 2, 22, rel); + + const uint32_t mask = 0x3FFFFF; + uint32_t insn = read32be(loc) & ~(mask); + uint32_t imm = extractBits(val, 23, 2); + insn |= imm; + write32be(loc,insn); + return; + } + case R_PATMOS_ALUI_ABS: { + // Relocate ALIi format (12 bit immediate), absolute (unsigned), in bytes + checkUInt(loc, static_cast(val), 12, rel); + + const uint32_t mask = 0xFFF; + uint32_t insn = read32be(loc) & ~(mask); + uint32_t imm = extractBits(val, 11, 0); + insn |= imm; + write32be(loc,insn); + return; + } + case R_PATMOS_ALUL_ABS: { + // Relocate ALUl format (32 bti immediate), absolute (unsigned), in bytes + checkUInt(loc, static_cast(val), 32, rel); + + const uint64_t mask = 0xFFFFFFFF; + uint64_t insn = read64be(loc) & ~(mask); + uint32_t imm = extractBits(val, 31, 0); + insn |= imm; + write64be(loc,insn); + return; + } + case R_PATMOS_MEMB_ABS:{ + // Relocate LDT or STT format (7 bit immediate), absolute, signed, in bytes + checkInt(loc, static_cast(val), 7, rel); + + const uint64_t mask = 0x7F; + uint32_t insn = read32be(loc) & ~(mask); + uint32_t imm = extractBits(val, 6, 0); + insn |= imm; + write32be(loc,insn); + return; + } + case R_PATMOS_MEMH_ABS:{ + // Relocate LDT or STT format (7 bit immediate), absolute, signed, in half-words + checkInt(loc, static_cast(val) >> 1, 7, rel); + + const uint64_t mask = 0x7F; + uint32_t insn = read32be(loc) & ~(mask); + uint32_t imm = extractBits(val, 7, 1); + insn |= imm; + write32be(loc,insn); + return; + } + case R_PATMOS_MEMW_ABS:{ + // Relocate LDT or STT format (7 bit immediate), absolute, signed, in words + checkInt(loc, static_cast(val) >> 2, 7, rel); + + const uint64_t mask = 0x7F; + uint32_t insn = read32be(loc) & ~(mask); + uint32_t imm = extractBits(val, 8, 2); + insn |= imm; + write32be(loc,insn); + return; + } + case R_PATMOS_ABS_32: { + // Relocate 32 bit word, absolute (unsigned), in bytes + checkUInt(loc, static_cast(val), 32, rel); + + uint64_t out = read32be(loc); + uint32_t temp = extractBits(val, 31, 0); + out += temp; + + checkIntUInt(loc, out, 32, rel); + + write32be(loc,out); + + return; + } + case R_PATMOS_CFLI_PCREL: { + // Relocate CFLi format (22 bit immediate), PC relative (signed), in words + checkInt(loc, static_cast(val) >> 2, 22, rel); + + const uint32_t mask = 0x3FFFFF; + uint32_t insn = read32be(loc) & ~(mask); + uint32_t imm = extractBits(val, 23, 2); + insn |= imm; + write32be(loc,insn); + return; + } + default: + llvm_unreachable("unknown relocation"); + } +} + +TargetInfo *elf::getPatmosTargetInfo() { + static Patmos target; + return ⌖ +} diff --git a/lld/ELF/CMakeLists.txt b/lld/ELF/CMakeLists.txt index f85d0fb9f55e..c90e9a21017c 100644 --- a/lld/ELF/CMakeLists.txt +++ b/lld/ELF/CMakeLists.txt @@ -12,6 +12,7 @@ add_lld_library(lldELF Arch/Mips.cpp Arch/MipsArchTree.cpp Arch/MSP430.cpp + Arch/Patmos.cpp Arch/PPC.cpp Arch/PPC64.cpp Arch/RISCV.cpp diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 3b2a8ba19293..d6aa8dfd1176 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -163,6 +163,7 @@ static std::tuple parseEmulation(StringRef emul) { .Case("elf_iamcu", {ELF32LEKind, EM_IAMCU}) .Case("elf64_sparc", {ELF64BEKind, EM_SPARCV9}) .Case("msp430elf", {ELF32LEKind, EM_MSP430}) + .Case("elf32-patmos", {ELF32BEKind, EM_PATMOS}) .Default({ELFNoneKind, EM_NONE}); if (ret.first == ELFNoneKind) diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index a23491d62dc8..e626a9c692db 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -1620,6 +1620,8 @@ static uint16_t getBitcodeMachineKind(StringRef path, const Triple &t) { return EM_MIPS; case Triple::msp430: return EM_MSP430; + case Triple::patmos: + return EM_PATMOS; case Triple::ppc: case Triple::ppcle: return EM_PPC; diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp index b81812d11821..7870e9f50a2e 100644 --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -427,6 +427,7 @@ static std::pair parseBfdName(StringRef s) { .Case("elf64-littleriscv", {ELF64LEKind, EM_RISCV}) .Case("elf64-sparc", {ELF64BEKind, EM_SPARCV9}) .Case("elf32-msp430", {ELF32LEKind, EM_MSP430}) + .Case("elf32-patmos", {ELF32BEKind, EM_PATMOS}) .Default({ELFNoneKind, EM_NONE}); } diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index cb816d8ed12d..47942e5ed9f3 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -77,6 +77,8 @@ TargetInfo *elf::getTarget() { } case EM_MSP430: return getMSP430TargetInfo(); + case EM_PATMOS: + return getPatmosTargetInfo(); case EM_PPC: return getPPCTargetInfo(); case EM_PPC64: diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h index 68b6c5d2ca35..28febb6f50ce 100644 --- a/lld/ELF/Target.h +++ b/lld/ELF/Target.h @@ -176,6 +176,7 @@ TargetInfo *getARMTargetInfo(); TargetInfo *getAVRTargetInfo(); TargetInfo *getHexagonTargetInfo(); TargetInfo *getMSP430TargetInfo(); +TargetInfo *getPatmosTargetInfo(); TargetInfo *getPPC64TargetInfo(); TargetInfo *getPPCTargetInfo(); TargetInfo *getRISCVTargetInfo(); diff --git a/lld/test/ELF/Patmos/lit.local.cfg b/lld/test/ELF/Patmos/lit.local.cfg new file mode 100644 index 000000000000..9513b895c689 --- /dev/null +++ b/lld/test/ELF/Patmos/lit.local.cfg @@ -0,0 +1,3 @@ + +# Only run tests when Patmos is available +config.unsupported = not(config.target_triple.startswith('patmos')) diff --git a/lld/test/ELF/Patmos/patmos-ABS32.s b/lld/test/ELF/Patmos/patmos-ABS32.s new file mode 100644 index 000000000000..dd78424fa5ad --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-ABS32.s @@ -0,0 +1,27 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf %s -o %t.o +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf %S/../Inputs/abs255.s -o %t255.o +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf %S/../Inputs/abs256.s -o %t256.o +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf %S/../Inputs/abs257.s -o %t257.o + +// RUN: ld.lld %t.o %t256.o -o %t2 +// RUN: llvm-objdump -s --section=.data %t2 | FileCheck %s +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Relocation Type R_PATMOS_ABS_32 +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.globl _start +_start: +.data + .word foo + 0xfffffeff + .word foo - 0x80000100 + +// : S = 0x100, A = 0xfffffeff +// S + A = 0xffffffff +// +4: S = 0x100, A = -0x80000100 +// S + A = 0x80000000 + +// CHECK: Contents of section .data: +// CHECK-NEXT: ffffffff 80000000 \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-ABS32_error.s b/lld/test/ELF/Patmos/patmos-ABS32_error.s new file mode 100644 index 000000000000..532915fdfdcc --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-ABS32_error.s @@ -0,0 +1,21 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf %s -o %t.o +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf %S/../Inputs/abs255.s -o %t255.o +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf %S/../Inputs/abs256.s -o %t256.o +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf %S/../Inputs/abs257.s -o %t257.o +// RUN: ld.lld %t.o %t255.o -o /dev/null +// RUN: not ld.lld %t.o %t257.o -o /dev/null 2>&1 | FileCheck %s +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Error for Out of Bound Values of Relocation Type R_PATMOS_ABS_32 +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.globl _start +_start: +.data + .word foo + 0xfffffeff + .word foo - 0x80000100 + +// CHECK: error +// CHECK: relocation Unknown (10) out of range: 4294967296 is not in [-2147483648, 4294967295] \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-ALU-ABS.s b/lld/test/ELF/Patmos/patmos-ALU-ABS.s new file mode 100644 index 000000000000..77223d3a08b8 --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-ALU-ABS.s @@ -0,0 +1,42 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf -mattr=-relax %s -o %t.patmos.o + +// RUN: ld.lld %t.patmos.o --defsym foo=2 -o %t.patmos +// RUN: llvm-objdump -d %t.patmos | FileCheck %s + +// Tests the maximum value (because values are unsigned) +// RUN: ld.lld %t.patmos.o --defsym foo=4095 -o %t2.o +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Relocation Types R_PATMOS_ALUI_ABS and R_PATMOS_ALUL_ABS +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.global _start +_start: + add $r1 = $r1, foo + sub $r1 = $r1, bar + xor $r1 = $r1, foo + sl $r1 = $r1, foo + sr $r1 = $r1, foo + sra $r1 = $r1, foo + or $r1 = $r1, foo + and $r1 = $r1, foo + nor $r1 = $r1, foo + shadd $r1 = $r1, foo + shadd2 $r1 = $r1, foo + +.global bar +bar = 255 + +// CHECK: 87 c2 10 00 00 00 00 02 add $r1 = $r1, 2 +// CHECK: 87 c2 10 01 00 00 00 ff sub $r1 = $r1, 255 +// CHECK: 87 c2 10 02 00 00 00 02 xor $r1 = $r1, 2 +// CHECK: 00 c2 10 02 sl $r1 = $r1, 2 +// CHECK: 01 02 10 02 sr $r1 = $r1, 2 +// CHECK: 01 42 10 02 sra $r1 = $r1, 2 +// CHECK: 87 c2 10 06 00 00 00 02 or $r1 = $r1, 2 +// CHECK: 87 c2 10 07 00 00 00 02 and $r1 = $r1, 2 +// CHECK: 87 c2 10 0b 00 00 00 02 nor $r1 = $r1, 2 +// CHECK: 87 c2 10 0c 00 00 00 02 shadd $r1 = $r1, 2 +// CHECK: 87 c2 10 0d 00 00 00 02 shadd2 $r1 = $r1, 2 \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-ALUI-ABS_error.s b/lld/test/ELF/Patmos/patmos-ALUI-ABS_error.s new file mode 100644 index 000000000000..319aaaebb60b --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-ALUI-ABS_error.s @@ -0,0 +1,20 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf -mattr=-relax %s -o %t.patmos.o +// RUN: not ld.lld %t.patmos.o --defsym foo=4096 -o %t.patmos 2>&1 | FileCheck %s +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Error for Out of Bound Values of Relocation Type R_PATMOS_ALUI_ABS +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.global _start +_start: + sl $r1 = $r1, foo + sr $r1 = $r1, bar + sra $r1 = $r1, bar + +.global bar +bar = 4096 + +// CHECK: error +// CHECK: relocation Unknown (3) out of range: 4096 is not in [0, 4095] \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-ALUL-ABS_error.s b/lld/test/ELF/Patmos/patmos-ALUL-ABS_error.s new file mode 100644 index 000000000000..b89efb5cb8f7 --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-ALUL-ABS_error.s @@ -0,0 +1,27 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf -mattr=-relax %s -o %t.patmos.o + +// RUN: not ld.lld %t.patmos.o --defsym foo=-1 -o %t.patmos 2>&1 | FileCheck %s +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Error for Out of Bound Values of Relocation Type R_PATMOS_ALUL_ABS +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.global _start +_start: + add $r1 = $r1, foo + sub $r1 = $r1, bar + xor $r1 = $r1, foo + or $r1 = $r1, foo + and $r1 = $r1, foo + nor $r1 = $r1, foo + shadd $r1 = $r1, foo + shadd2 $r1 = $r1, foo + +.global bar +bar = 4294967296 + + +// CHECK: error +// CHECK: relocation Unknown (5) out of range: 18446744073709551615 is not in [0, 4294967295] \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-CFLI-ABS-callnd.s b/lld/test/ELF/Patmos/patmos-CFLI-ABS-callnd.s new file mode 100644 index 000000000000..702cfef41082 --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-CFLI-ABS-callnd.s @@ -0,0 +1,22 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf -mattr=-relax %s -o %t.patmos.o + +// RUN: ld.lld %t.patmos.o --defsym foo=0 --defsym bar=8 -o %t.patmos +// RUN: llvm-objdump -d %t.patmos | FileCheck %s + +// Tests the maximum value (because values are unsigned) +// RUN: ld.lld %t.patmos.o --defsym foo=16777215 --defsym bar=8 -o %t2 + +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Relocation Type R_PATMOS_CFLI_ABS +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.global _start +_start: + call foo + call bar + +// CHECK: 04 40 00 00 call 0 +// CHECK: 04 40 00 02 call 2 \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-CFLI-ABS_error.s b/lld/test/ELF/Patmos/patmos-CFLI-ABS_error.s new file mode 100644 index 000000000000..40a51ba60749 --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-CFLI-ABS_error.s @@ -0,0 +1,19 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf -mattr=-relax %s -o %t.patmos.o +// RUN: not ld.lld %t.patmos.o --defsym foo=16777216 --defsym bar=8 -o %t.patmos 2>&1 | FileCheck %s +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Error for Out of Bound Values of Relocation Type R_PATMOS_CFLI_ABS +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.global _start +_start: + call foo + call bar + +.global bar +bar = -5 + +// CHECK: error +// CHECK: relocation Unknown (1) out of range: 4194304 is not in [0, 4194303] \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-CFLI-PCREL.s b/lld/test/ELF/Patmos/patmos-CFLI-PCREL.s new file mode 100644 index 000000000000..6442823bea98 --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-CFLI-PCREL.s @@ -0,0 +1,29 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf -mattr=-relax %s -o %t.patmos.o + +// RUN: ld.lld %t.patmos.o -o %t.patmos +// RUN: llvm-objdump -d %t.patmos | FileCheck %s +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Relocation Type R_PATMOS_CFLI_PCREL +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.global _start +_start: + br bar + br foo + nop + nop + +.global foo, bar +foo: + nop +bar: + nop + nop + brnd foo + +// CHECK: 04 c0 00 05 br 5 +// CHECK: 04 c0 00 03 br 3 +// CHECK: 04 bf ff fd brnd -3 \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-CFLI-PCREL_error.s b/lld/test/ELF/Patmos/patmos-CFLI-PCREL_error.s new file mode 100644 index 000000000000..b1fb9092c613 --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-CFLI-PCREL_error.s @@ -0,0 +1,25 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf -mattr=-relax %s -o %t.patmos.o + +// RUN: not ld.lld %t.patmos.o -o %t.patmos --defsym bar=16777216 2>&1 | FileCheck %s +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Error for Out of Bound Values of Relocation Type R_PATMOS_CFLI_PCREL +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.global _start +_start: + br bar + br foo + nop + nop + +.global foo, bar +foo: + nop +bar: + nop + +// CHECK: error +// CHECK: relocation Unknown (12) out of range: 4160467 is not in [-2097152, 2097151] \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-MEMB-ABS.s b/lld/test/ELF/Patmos/patmos-MEMB-ABS.s new file mode 100644 index 000000000000..a7af4617ea67 --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-MEMB-ABS.s @@ -0,0 +1,25 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf -mattr=-relax %s -o %t.patmos.o + +// RUN: ld.lld %t.patmos.o --defsym foo=16 --defsym bar=32 -o %t.patmos +// RUN: llvm-objdump -d %t.patmos | FileCheck %s + +// Tests the minimal and the maximum value +// RUN: ld.lld %t.patmos.o --defsym foo=63 --defsym bar=-64 -o %t2.o +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Relocation Type R_PATMOS_MEMB_ABS +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.global _start +_start: + lbs $r1 = [$r2 + foo] + lbl $r1 = [$r2 + foo] + lbc $r1 = [$r2 + bar] + lbm $r1 = [$r2 + bar] + +// CHECK: 02 82 24 10 lbs $r1 = [$r2 + 16] +// CHECK: 02 82 24 90 lbl $r1 = [$r2 + 16] +// CHECK: 02 82 25 20 lbc $r1 = [$r2 + 32] +// CHECK: 02 82 25 a0 lbm $r1 = [$r2 + 32] \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-MEMB-ABS_error.s b/lld/test/ELF/Patmos/patmos-MEMB-ABS_error.s new file mode 100644 index 000000000000..c596845018d5 --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-MEMB-ABS_error.s @@ -0,0 +1,20 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf -mattr=-relax %s -o %t.patmos.o +// RUN: not ld.lld %t.patmos.o --defsym foo=64 --defsym bar=-65 -o %t.patmos 2>&1 | FileCheck %s +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Error for Out of Bound Values of Relocation Type R_PATMOS_MEMB_ABS +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.global _start +_start: + lbs $r1 = [$r2 + foo] + lbl $r1 = [$r2 + foo] + lbc $r1 = [$r2 + bar] + lbm $r1 = [$r2 + bar] + +// CHECK: error +// CHECK: relocation Unknown (7) out of range: 64 is not in [-64, 63] +// CHECK: error +// CHECK: relocation Unknown (7) out of range: -65 is not in [-64, 63] \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-MEMH-ABS.s b/lld/test/ELF/Patmos/patmos-MEMH-ABS.s new file mode 100644 index 000000000000..c91b5fbe49c1 --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-MEMH-ABS.s @@ -0,0 +1,27 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf -mattr=-relax %s -o %t.patmos.o + +// RUN: ld.lld %t.patmos.o --defsym foo=16 --defsym bar=32 -o %t.patmos +// RUN: llvm-objdump -d %t.patmos | FileCheck %s + +// Tests the minimal and the maximum value +// RUN: ld.lld %t.patmos.o --defsym foo=127 --defsym bar=-128 -o %t2.o +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Relocation Type R_PATMOS_MEMH_ABS +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.global _start +_start: + lhs $r1 = [$r2 + foo] + lhl $r1 = [$r2 + foo] + lhc $r1 = [$r2 + bar] + lhm $r1 = [$r2 + bar] + + + +// CHECK: 02 82 22 08 lhs $r1 = [$r2 + 8] +// CHECK: 02 82 22 88 lhl $r1 = [$r2 + 8] +// CHECK: 02 82 23 10 lhc $r1 = [$r2 + 16] +// CHECK: 02 82 23 90 lhm $r1 = [$r2 + 16] \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-MEMH-ABS_error.s b/lld/test/ELF/Patmos/patmos-MEMH-ABS_error.s new file mode 100644 index 000000000000..3861942d2018 --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-MEMH-ABS_error.s @@ -0,0 +1,20 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf -mattr=-relax %s -o %t.patmos.o +// RUN: not ld.lld %t.patmos.o --defsym foo=128 --defsym bar=-129 -o %t.patmos 2>&1 | FileCheck %s +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Error for Out of Bound Values of Relocation Type R_PATMOS_MEMH_ABS +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.global _start +_start: + lhs $r1 = [$r2 + foo] + lhl $r1 = [$r2 + foo] + lhc $r1 = [$r2 + bar] + lhm $r1 = [$r2 + bar] + +// CHECK: error +// CHECK: relocation Unknown (8) out of range: 64 is not in [-64, 63] +// CHECK: error +// CHECK: relocation Unknown (8) out of range: -65 is not in [-64, 63] \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-MEMW-ABS.s b/lld/test/ELF/Patmos/patmos-MEMW-ABS.s new file mode 100644 index 000000000000..1211147beac0 --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-MEMW-ABS.s @@ -0,0 +1,25 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf -mattr=-relax %s -o %t.patmos.o + +// RUN: ld.lld %t.patmos.o --defsym foo=16 --defsym bar=32 -o %t.patmos +// RUN: llvm-objdump -d %t.patmos | FileCheck %s + +// Tests the minimal and the maximum value +// RUN: ld.lld %t.patmos.o --defsym foo=255 --defsym bar=-256 -o %t.patmos +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Relocation Type R_PATMOS_MEMW_ABS +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.global _start +_start: + lws $r1 = [$r2 + foo] + lwl $r1 = [$r2 + foo] + lwc $r1 = [$r2 + bar] + lwm $r1 = [$r2 + bar] + +// CHECK: 02 82 20 04 lws $r1 = [$r2 + 4] +// CHECK: 02 82 20 84 lwl $r1 = [$r2 + 4] +// CHECK: 02 82 21 08 lwc $r1 = [$r2 + 8] +// CHECK: 02 82 21 88 lwm $r1 = [$r2 + 8] \ No newline at end of file diff --git a/lld/test/ELF/Patmos/patmos-MEMW-ABS_error.s b/lld/test/ELF/Patmos/patmos-MEMW-ABS_error.s new file mode 100644 index 000000000000..04f9b4fedacc --- /dev/null +++ b/lld/test/ELF/Patmos/patmos-MEMW-ABS_error.s @@ -0,0 +1,20 @@ +// RUN: llvm-mc -filetype=obj -triple=patmos-unknown-unknown-elf -mattr=-relax %s -o %t.patmos.o +// RUN: not ld.lld %t.patmos.o --defsym foo=256 --defsym bar=-257 -o %t.patmos 2>&1 | FileCheck %s +// END. +/////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Tests the Error for Out of Bound Values of Relocation Type R_PATMOS_MEMW_ABS +// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +.global _start +_start: + lws $r1 = [$r2 + foo] + lwl $r1 = [$r2 + foo] + lwc $r1 = [$r2 + bar] + lwm $r1 = [$r2 + bar] + +// CHECK: error +// CHECK: relocation Unknown (9) out of range: 64 is not in [-64, 63] +// CHECK: error +// CHECK: relocation Unknown (9) out of range: -65 is not in [-64, 63] \ No newline at end of file diff --git a/lld/test/lit.cfg.py b/lld/test/lit.cfg.py index 670f41f0b631..a68a00ddb246 100644 --- a/lld/test/lit.cfg.py +++ b/lld/test/lit.cfg.py @@ -72,6 +72,7 @@ 'Hexagon': 'hexagon', 'Mips': 'mips', 'MSP430': 'msp430', + 'Patmos': 'patmos', 'PowerPC': 'ppc', 'RISCV': 'riscv', 'Sparc': 'sparc', diff --git a/llvm/cmake/platforms/Patmos.cmake b/llvm/cmake/platforms/Patmos.cmake index 2728ba4edb79..4e9d64037e0f 100644 --- a/llvm/cmake/platforms/Patmos.cmake +++ b/llvm/cmake/platforms/Patmos.cmake @@ -7,7 +7,7 @@ set( PACKAGE_TEMP_DIR "${PATMOS_TRIPLE}/package-temp") set( PACKAGE_TAR "${PACKAGE_TEMP_DIR}/${PROJECT_NAME}-${TARGET_TRIPLE}.tar") set( PACKAGE_TAR_GZ "${PACKAGE_TAR}.gz") set( PACKAGE_INFO_FILE "${PACKAGE_TEMP_DIR}/${PROJECT_NAME}-info.yml") -set( PACKAGE_TARGETS "llc" "llvm-link" "clang" "llvm-config" "llvm-objdump" "opt") +set( PACKAGE_TARGETS "llc" "llvm-link" "clang" "llvm-config" "llvm-objdump" "opt" "lld") set( PACKAGE_ITEMS_LIBS "${PACKAGE_TEMP_DIR}/${PATMOS_TRIPLE}/lib/crt0.o" "${PACKAGE_TEMP_DIR}/${PATMOS_TRIPLE}/lib/crtbegin.o" @@ -29,11 +29,12 @@ set( NEWLIB_INCLUDES # List of dirs from which to get only the files ) set( PACKAGE_ITEMS # Package binaries - "bin/llc" "bin/llvm-link" "bin/clang-12" "bin/llvm-config" "bin/llvm-objdump" "bin/opt" + "bin/llc" "bin/llvm-link" "bin/clang-12" "bin/llvm-config" "bin/llvm-objdump" "bin/opt" "bin/lld" # Moved binaries "${PACKAGE_TEMP_DIR}/bin/clang" # Actually a symlink - + "${PACKAGE_TEMP_DIR}/bin/ld.lld" # Actually a symlink + # Clang headers "lib/clang" @@ -73,8 +74,9 @@ add_custom_command( COMMAND rsync "../patmos-newlib/newlib/libc/machine/patmos/include/*" "${PACKAGE_TEMP_DIR}/${PATMOS_TRIPLE}/include/" ) -ADD_CUSTOM_TARGET(symlink-clang +ADD_CUSTOM_TARGET(symlink-clang-lld COMMAND ${CMAKE_COMMAND} -E create_symlink patmos-clang-12 ${PACKAGE_TEMP_DIR}/bin/clang + COMMAND ${CMAKE_COMMAND} -E create_symlink patmos-lld ${PACKAGE_TEMP_DIR}/bin/ld.lld DEPENDS clang PatmosPackageTempDirs ) # Build release tarball containing binaries and metadata @@ -109,7 +111,7 @@ add_custom_command( # Compress the tar COMMAND gzip -9 < ${PACKAGE_TAR} > ${PACKAGE_TAR_GZ} - DEPENDS ${PACKAGE_TARGETS} ${PACKAGE_ITEMS_LIBS} symlink-clang "${PACKAGE_TEMP_DIR}/${PATMOS_TRIPLE}/include/newlib.h" + DEPENDS ${PACKAGE_TARGETS} ${PACKAGE_ITEMS_LIBS} symlink-clang-lld "${PACKAGE_TEMP_DIR}/${PATMOS_TRIPLE}/include/newlib.h" ) # Rename release tarball target to something better. add_custom_target(PatmosPackage DEPENDS ${PACKAGE_TAR_GZ}) \ No newline at end of file diff --git a/llvm/test/CodeGen/Patmos/README.md b/llvm/test/CodeGen/Patmos/README.md index 4b93cb2e25aa..2759b03b047e 100644 --- a/llvm/test/CodeGen/Patmos/README.md +++ b/llvm/test/CodeGen/Patmos/README.md @@ -19,7 +19,7 @@ for easy test setup. Used to test files by compiling and running them, ensuring 0 is returned. -This uses LLC and patmos-ld to compile the LLVM-IR test program without any +This uses LLC and ld.lld to compile the LLVM-IR test program without any standard library or runtime code of any kind, producing a standalone ELF that is then run on pasim. diff --git a/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/align_multiple_subfunctions.ll b/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/align_multiple_subfunctions.ll index 950e4bb12de3..b08050147850 100644 --- a/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/align_multiple_subfunctions.ll +++ b/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/align_multiple_subfunctions.ll @@ -1,6 +1,6 @@ ; RUN: llc < %s -mpatmos-subfunction-align=32 -mpatmos-max-subfunction-size=64| FileCheck %s ; RUN: llc < %s -mpatmos-subfunction-align=32 -mpatmos-max-subfunction-size=64 -filetype=obj -o %t;\ -; RUN: patmos-ld %t -nostdlib -static -o %t --section-start .text=1;\ +; RUN: ld.lld %t --nostdlib --static -o %t --section-start .text=1;\ ; RUN: llvm-objdump %t -d| FileCheck %s --check-prefix ALIGN ; RUN: LLC_ARGS="-mpatmos-subfunction-align=32 -mpatmos-max-subfunction-size=64";\ ; RUN: PASIM_ARGS="--mcsize=64"; %test_no_runtime_execution diff --git a/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/set_align_32.ll b/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/set_align_32.ll index c5fd4fe3dadc..a08bb367ed5c 100644 --- a/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/set_align_32.ll +++ b/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/set_align_32.ll @@ -1,6 +1,6 @@ ; RUN: llc < %s -mpatmos-subfunction-align=32 | FileCheck %s ; RUN: llc < %s -mpatmos-subfunction-align=32 -filetype=obj -o %t;\ -; RUN: patmos-ld %t -nostdlib -static -o %t --section-start .text=1;\ +; RUN: ld.lld %t --nostdlib --static -o %t --section-start .text=1;\ ; RUN: llvm-objdump %t -d | FileCheck %s --check-prefix ALIGN ; RUN: LLC_ARGS="-mpatmos-subfunction-align=32"; %test_no_runtime_execution ; END. @@ -12,7 +12,7 @@ ; 1. We ensure that when outputting assembly, the function is preceded by the alignment. ; 2. We check that when outputting object code the address of the first instuction ; in the function is aligned correctly. -; We use patmos-ld to start the .text section at address 1, +; We use ld.lld to start the .text section at address 1, ; which is never a valid alignment. ; We then to the check using llvm-objdump and the "ALIGN" prefix for FileCheck. ; We then check that the address after the main label ends in the correct values diff --git a/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/set_align_4.ll b/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/set_align_4.ll index 30f7e512240d..25158169dd37 100644 --- a/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/set_align_4.ll +++ b/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/set_align_4.ll @@ -1,6 +1,6 @@ ; RUN: llc < %s -mpatmos-subfunction-align=4 | FileCheck %s ; RUN: llc < %s -mpatmos-subfunction-align=4 -filetype=obj -o %t;\ -; RUN: patmos-ld %t -nostdlib -static -o %t --section-start .text=1;\ +; RUN: ld.lld %t --nostdlib --static -o %t --section-start .text=1;\ ; RUN: llvm-objdump %t -d | FileCheck %s --check-prefix ALIGN ; RUN: LLC_ARGS="-mpatmos-subfunction-align=4"; %test_no_runtime_execution ; END. @@ -12,7 +12,7 @@ ; 1. We ensure that when outputting assembly, the function is preceded by the alignment. ; 2. We check that when outputting object code the address of the first instuction ; in the function is aligned correctly. -; We use patmos-ld to start the .text section at address 1, +; We use ld.lld to start the .text section at address 1, ; which is never a valid alignment. ; We then to the check using llvm-objdump and the "ALIGN" prefix for FileCheck. ; We then check that the address after the main label ends in the correct values diff --git a/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/set_align_8.ll b/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/set_align_8.ll index aeab437159a8..92c7e703a67c 100644 --- a/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/set_align_8.ll +++ b/llvm/test/CodeGen/Patmos/flags/mpatmos-subfunction-align/set_align_8.ll @@ -1,6 +1,6 @@ ; RUN: llc < %s -mpatmos-subfunction-align=8 | FileCheck %s ; RUN: llc < %s -mpatmos-subfunction-align=8 -filetype=obj -o %t;\ -; RUN: patmos-ld %t -nostdlib -static -o %t --section-start .text=1;\ +; RUN: ld.lld %t --nostdlib --static -o %t --section-start .text=1;\ ; RUN: llvm-objdump %t -d | FileCheck %s --check-prefix ALIGN ; RUN: LLC_ARGS="-mpatmos-subfunction-align=8"; %test_no_runtime_execution ; END. @@ -12,7 +12,7 @@ ; 1. We ensure that when outputting assembly, the function is preceded by the alignment. ; 2. We check that when outputting object code the address of the first instuction ; in the function is aligned correctly. -; We use patmos-ld to start the .text section at address 1, +; We use ld.lld to start the .text section at address 1, ; which is never a valid alignment. ; We then to the check using llvm-objdump and the "ALIGN" prefix for FileCheck. ; We then check that the address after the main label ends in the correct values diff --git a/llvm/test/CodeGen/Patmos/lit.local.cfg b/llvm/test/CodeGen/Patmos/lit.local.cfg index 2bc39b58f4c5..c077f4a378cb 100644 --- a/llvm/test/CodeGen/Patmos/lit.local.cfg +++ b/llvm/test/CodeGen/Patmos/lit.local.cfg @@ -15,7 +15,7 @@ config.substitutions.append(('%test_no_runtime_execution', # Compile startup function "llc " + _start_file + " -filetype=obj -o %t_lit_cfg_start && \\\n" + # Link program and startup function and emit ELF - "patmos-ld -nostdlib -static -o %t %t_lit_cfg_start %t_lit_cfg_compiled $LD_ARGS && \\\n" + + "ld.lld --nostdlib --static -o %t %t_lit_cfg_start %t_lit_cfg_compiled $LD_ARGS && \\\n" + # Run program "pasim %t -c 800 $PASIM_ARGS" )) diff --git a/llvm/test/CodeGen/Patmos/programs/bounded/assert_correct.py b/llvm/test/CodeGen/Patmos/programs/bounded/assert_correct.py index a5142d1962fe..6aa888e5d360 100644 --- a/llvm/test/CodeGen/Patmos/programs/bounded/assert_correct.py +++ b/llvm/test/CodeGen/Patmos/programs/bounded/assert_correct.py @@ -3,10 +3,6 @@ import sys from shutil import which -if which("patmos-ld") is None: - print("Patmos port of the Gold linker 'patmos-ld' could not be found.") - sys.exit(1) - if which("pasim") is None: print("Patmos simulator 'pasim' could not be found.") sys.exit(1) @@ -104,7 +100,7 @@ def execute_and_stat(program, args): exec_name = program + input # Final generation of ELF with added input - if subprocess.run(["patmos-ld", "-nostdlib", "-static", "-o", exec_name, program, + if subprocess.run(["ld.lld", "-nostdlib", "-static", "-o", exec_name, program, "--defsym", "input=" + input]).returncode != 0: return True, args + "\nFailed to generate executable from '" + program + "' for argument '" + input + "'"