Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Pull Request - LLD Port to Patmos #4

Merged
merged 23 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6d88c63
[Patmos][lld] Add Patmos.cpp in lld Targets
haraldschn Dec 7, 2021
57fe7d3
[Patmos][lld] Relocation - CFLI_ABS and CFLI_PCREL
haraldschn Dec 8, 2021
cf58418
[Patmos][lld] Added Relocations + Deleted Methods for PLT and GOT
haraldschn Dec 21, 2021
a115edd
[Patmos][lld] SUPPORTED Tests + README for lld with Patmos
haraldschn Dec 21, 2021
c37292d
[Patmos][lld] Readme.Patmos fix
haraldschn Jan 4, 2022
f99c772
[Patmos][lld] Fix bug in Patmos.cpp for Relocation ABS32
haraldschn Jan 6, 2022
eb29602
[Patmos][lld] Test Relocations 1
haraldschn Jan 11, 2022
ca4e555
[Patmos][lld] Cleanup Patmos.cpp
haraldschn Jan 12, 2022
7efd34d
[Patmos][lld] Testcases LLVM Patmos
haraldschn Jan 12, 2022
5b782f5
[Patmos][lld] Test Clang with lld
haraldschn Jan 26, 2022
84545d0
[Patmos][lld] Disable patmos-ld check for LLVMtest
haraldschn Jan 26, 2022
757c5e0
[Patmos][lld] Adapt action.yml for LLD
haraldschn Feb 7, 2022
4521762
[Patmos][lld] Add lld to checkout for actions
haraldschn Feb 8, 2022
2b166bf
[Patmos][lld] Actions - add LLD Tests
haraldschn Feb 8, 2022
ce26e2a
[Patmos][lld] fix input-checks + test edgecases
haraldschn Feb 8, 2022
a173c0f
[Patmos][lld] testing - add requires: patmos
haraldschn Feb 8, 2022
1230c04
[Patmos][lld] adapt README to include LLD
haraldschn Feb 9, 2022
f5bac4d
[Patmos][lld] Remove REAME-Patmos in LLD
haraldschn Mar 8, 2022
6c8cc0f
[Patmos][lld] Github Actions without GOLD
haraldschn Mar 8, 2022
5a54402
[Patmos][lld] Fix clang call for lld
haraldschn Mar 8, 2022
4ef687e
[Patmos][lld] Add -O0 to LLD call in Clang
haraldschn Mar 12, 2022
4c566ce
[Patmos][lld] Add Comments - fix README
haraldschn Mar 13, 2022
f20af8e
[Patmos][lld] Fixes to PR Review
haraldschn Mar 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/actions/build-test-all/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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}})
Expand Down Expand Up @@ -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
7 changes: 1 addition & 6 deletions .github/workflows/patmos-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
11 changes: 8 additions & 3 deletions README-Patmos.MD
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ tar -xvf <tarfile>
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

Expand Down Expand Up @@ -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
Emoun marked this conversation as resolved.
Show resolved Hide resolved
```

### Build
Expand All @@ -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
```

Expand Down Expand Up @@ -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:

```
Expand Down
30 changes: 12 additions & 18 deletions clang/lib/Driver/ToolChains/Patmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Emoun marked this conversation as resolved.
Show resolved Hide resolved
char *gold_envvar = getenv("PATMOS_GOLD");
if (gold_envvar && strcmp(gold_envvar,"")!=0 ) {
Expand All @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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<Command>(
JA, Creator, ResponseFileSupport::AtFileCurCP(),
LDExec, LDArgs, Inputs, Output));
Expand Down Expand Up @@ -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);

}

4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/Patmos.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
14 changes: 0 additions & 14 deletions clang/test/Driver/Patmos/default-patmos-gold.c

This file was deleted.

2 changes: 1 addition & 1 deletion compiler-rt/test/builtins/Unit/patmos/lit.local.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading