lbd's People
Forkers
vvlevchenko serge1 wind0136 diamondman zysyyz floatingguy jakoberzar ychclone amesianx happybaoliang neo-vincent stjordanis abhi5658054 llyuer qshan nmtrmail gaybro8777 disdi lianghongkey zhangboyue nirvananimbusa fullstackhan ewenwan joyxu milossubotic peter9606 huntershuai zhutony ggangliu gfvvz kingkongtree marcelvdh lituo33 13zsh wjh-la jayef0 xubenji varlardohaeris tiaanl mengxianglinx gmh5225 shonker jimmyhongjichuan amanda-barbara xzhao23 posticarus takeshineshiro suisui-koubou tjzhou23 newmai goog00 shanshuixiliu xengpro mrrobbin qubinghuo-source andreww0210 kingrobotzhou reheher s311354 ruhung stone0107 jang1664lbd's Issues
Build Issue
Hi, I encounter a build issue and I don't know how to fix it, maybe it's my environment issue.
Does anybody can help me ? Thanks : )
the CMakeError.log"
is :
Checking whether the ASM compiler is GNU using "--version" did not match "(GNU assembler)|(GCC)|(Free Software Foundation)":
clang version 17.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /media/Workspace/llvm/debug/build/bin
Performing C++ SOURCE FILE Test LLVM_LIBSTDCXX_MIN failed with the following output:
Change Dir: /media/Workspace/llvm/test/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/ninja cmTC_9b05f && [1/2] Building CXX object CMakeFiles/cmTC_9b05f.dir/src.cxx.o
FAILED: CMakeFiles/cmTC_9b05f.dir/src.cxx.o
/media/Workspace/llvm/debug/build/bin/clang++ -DLLVM_LIBSTDCXX_MIN -std=c++0x -std=c++14 -MD -MT CMakeFiles/cmTC_9b05f.dir/src.cxx.o -MF CMakeFiles/cmTC_9b05f.dir/src.cxx.o.d -o CMakeFiles/cmTC_9b05f.dir/src.cxx.o -c /media/Workspace/llvm/test/build/CMakeFiles/CMakeTmp/src.cxx
/media/Workspace/llvm/test/build/CMakeFiles/CMakeTmp/src.cxx:2:10: fatal error: 'iosfwd' file not found
2 | #include <iosfwd>
| ^~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.
Source file was:
#include <iosfwd>
#if defined(__GLIBCXX__)
#if !defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE < 7
#error Unsupported libstdc++ version
#endif
#endif
int main() { return 0; }
Use ChatGPT to improve this tutorial
Hi Jonathan,
Iโm impressed with the amount of effort you have put into writing this tutorial. But to be frank, the amount of spelling and grammatical mistakes in this make it painful to read. Of course, I get where you are coming from given that both of us are non-native English speakers. For me personally, ChatGPT has come through in a lot of different language-related situations. For instance, it may help you with the following prompt:
You are a technical writer for the LLVM infrastructure. The following paragraphs contain numerous linguistical errata. Please correct the following paragraphs in a scientific and technical tone.
If you want to, I may assist you with correcting your tutorial by opening PRs.
Installing LLVM and the Cpu0 example code
Hello, dear friends!
I am trying to install LLVM and the Cpu0 example code following:
"Appendix A: Getting Started: Installing LLVM and the Cpu0 example code" instructions.
Everything builds ithout a problem, but when the installation is completed, folder Examplecode/lbdex/InputFiles is missing in this location:
~/llvm/test/src/lib/Target/Cpu0/ExampleCode/lbdex/InputFiles.
I downloaded lbdex archive from here: http://jonathan2251.github.io/lbd/lbdex.tar.gz.
I have repeated the installation several times with the same result...
My OS is Debian 4.9.13 Kali
Hope you can help! Thanks in advance!
Failed to build with LLVM 17
I'm compiling the Cpu0 code with LLVM 17, and get below error message:
FAILED: lib/Target/Cpu0/MCTargetDesc/CMakeFiles/LLVMCpu0Desc.dir/Cpu0MCTargetDesc.cpp.o
/usr/sbin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D_LIBCPP_ENABLE_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/root/projects/llvm-project/llvm/build/lib/Target/Cpu0/MCTargetDesc -I/root/projects/llvm-project/llvm/lib/Target/Cpu0/MCTargetDesc -I/root/projects/llvm-project/llvm/lib/Target/Cpu0 -I/root/projects/llvm-project/llvm/build/lib/Target/Cpu0 -I/root/projects/llvm-project/llvm/build/include -I/root/projects/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fvisibility=hidden -fno-exceptions -funwind-tables -fno-rtti -std=c++17 -MD -MT lib/Target/Cpu0/MCTargetDesc/CMakeFiles/LLVMCpu0Desc.dir/Cpu0MCTargetDesc.cpp.o -MF lib/Target/Cpu0/MCTargetDesc/CMakeFiles/LLVMCpu0Desc.dir/Cpu0MCTargetDesc.cpp.o.d -o lib/Target/Cpu0/MCTargetDesc/CMakeFiles/LLVMCpu0Desc.dir/Cpu0MCTargetDesc.cpp.o -c /root/projects/llvm-project/llvm/lib/Target/Cpu0/MCTargetDesc/Cpu0MCTargetDesc.cpp
In file included from /root/projects/llvm-project/llvm/lib/Target/Cpu0/MCTargetDesc/Cpu0MCTargetDesc.cpp:34:
/root/projects/llvm-project/llvm/build/lib/Target/Cpu0/Cpu0GenSubtargetInfo.inc:74:57: warning: zero size arrays are an extension [-Wzero-length-array]
extern const llvm::SubtargetSubTypeKV Cpu0SubTypeKV[] = {
^
/root/projects/llvm-project/llvm/build/lib/Target/Cpu0/Cpu0GenSubtargetInfo.inc:105:73: error: use of undeclared identifier 'None'
return new Cpu0GenMCSubtargetInfo(TT, CPU, TuneCPU, FS, std::nullopt, None,
^
1 warning and 1 error generated.
I've tried to solve it by myself, but as a newbie, it's really hard.
What should I do to fix the "use of undeclared identifier" issue? Seems there is something missing.
Configuration and compilation commands (the working directory is llvm-project/llvm):
$ cmake -S . -B build -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug
$ cmake --build build --target all
build-llvm.sh Error
Hello Jonathan,
I am new in LLVM.
Using Ubuntu 20.04, it seems that the build-llvm.sh does not download the llvm-project properly:
bash build-llvm.sh
~/llvm ~/git/lbd/lbdex/install_llvm
Cloning into 'llvm-project'...
fatal: unable to connect to github.com:
github.com[0: 192.30.255.113]: errno=Connection timed out
build-llvm.sh: line 11: cd: llvm-project: No such file or directory
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
cp: cannot stat 'llvm-project/clang': No such file or directory
cp: cannot stat 'llvm-projHello Jonathan,
I am new in LLVM.
Using Ubuntu 20.04, it seems that the build-llvm.sh does not download the llvm-project properly:
bash build-llvm.sh
~/llvm ~/git/lbd/lbdex/install_llvm
Cloning into 'llvm-project'...
fatal: unable to connect to github.com:
github.com[0: 192.30.255.113]: errno=Connection timed out
build-llvm.sh: line 11: cd: llvm-project: No such file or directory
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
cp: cannot stat 'llvm-project/clang': No such file or directory
cp: cannot stat 'llvm-project/llvm': No such file or directory
cp: cannot stat 'llvm-project/compiler-rt': No such file or directory
~/llvm/release/build ~ ~/git/lbd/lbdex/install_llvm
OS = Linux
CMake Error: The source directory "/home//llvm/release/llvm" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
ninja: error: loading 'build.ninja': No such file or directory
~ ~/git/lbd/lbdex/install_llvm
~/git/lbd/lbdex/install_llvm
Please remember to add ${HOME}/llvm/release/bin to variable ${PATH} to your environment for clang++, clang.ect/llvm': No such file or directory
cp: cannot stat 'llvm-project/compiler-rt': No such file or directory
~/llvm/release/build ~ ~/git/lbd/lbdex/install_llvm
OS = Linux
CMake Error: The source directory "/home//llvm/release/llvm" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
ninja: error: loading 'build.ninja': No such file or directory
~ ~/git/lbd/lbdex/install_llvm
~/git/lbd/lbdex/install_llvm
Please remember to add ${HOME}/llvm/release/bin to variable ${PATH} to your environment for clang++, clang.
Triple.h has moved from ADT to TargetParser
Hey,
I am reading this book and noticed that the Triple.h
, which is referenced here (https://jonathan2251.github.io/lbd/llvmstructure.html#cpu0-backend-machine-id-and-relocation-records), is not correct anymore. It was moved to TargetParser
.
Old folder: https://github.com/llvm/llvm-project/tree/main/llvm/include/llvm/ADT
New: https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/TargetParser/Triple.h#L44
How to compile the code in the chapter2?
Hello, Jonathan. You tell us how to transfer the LLVM IR into the target CPU instructions in this http://jonathan2251.github.io/lbd/llvmstructure.html
. I learned a lot. but I am still confused that how to compile the code in chapter2. Could you list the steps to compile the code in chapter2? Thank you very much!
Benji Xu
varargs causing segfaults?
Hello Jonathan!
I am having problems with vararg support in the Cpu0 backend implementation.
In short, it's this piece of code.
It saves varargs originally passed in registers onto stacks. But it sometimes goes out of the stack frame of the original function. I guess it's because when computing the stack size, varargs are not taken into account.
Below is my example:
For the following C code
#include <stdarg.h>
unsigned sum(unsigned amount, ...)
{
unsigned i = 0;
unsigned val = 0;
unsigned sum = 0;
va_list vl;
va_start(vl, amount);
for (i = 0; i < amount; i++) {
val = va_arg(vl, unsigned);
sum += val;
}
va_end(vl);
return sum;
}
llc generates the assembly
......
.type sum,@function
.ent sum # @sum
sum:
.frame $fp,24,$lr
.mask 0x00001000,-4
.set noreorder
.set nomacro
# BB#0:
addiu $sp, $sp, -24
st $fp, 20($sp) # 4-byte Folded Spill
move $fp, $sp
st $5, 28($fp)
st $4, 16($fp)
......
The stack frame is only 24 bytes large, but it's trying to do st $5, 28($fp)
. so it's storing $5
beyond sum
's stack frame, which causes segfaults in some cases.
Is it a bug or have I made any mistakes?
My environment:
- Ubuntu 16.04 64bit
- clang 3.8
- llvm 3.9 (the same as in your backend tutorial)
The command I used to generate assembly:
clang -target mips-unknown-linux-gnu -O0 -emit-llvm -c test.c
../llc -march=cpu0el -relocation-model=static -filetype=asm test.bc -o test.s
tblgen for "Cpu0GenCodeEmitter.inc" failed
hi, @Jonathan2251:
When I tried to generate the "Cpu0GenCodeEmitter.inc" with tablegen(LLVM Cpu0GenCodeEmitter.inc -gen-emitter)
, It failed with the following message.
lib/Target/Cpu0/Cpu0InstrInfo.td:1037:5: error: No operand named addr in record JSUB
def JSUB : JumpLink<0x3b, "jsub">;
^
note: Dumping record for previous error:
much more messages ...
Finally, I found the "FJ" in "Cpu0InstrFormats.td" has defined "bits<24> addr;" field,
however, the "class JumpLink" adopt the "$target" as follows.
let isCall=1, hasDelaySlot=1 in {
//@JumpLink {
class JumpLink<bits<8> op, string instr_asm>:
- FJ<op, (outs), (ins calltarget:$target, variable_ops),
- !strconcat(instr_asm, "\t$target"), [(Cpu0JmpLink imm:$target)],
IIBranch> {
//#if CH >= CH10_1 2
let DecoderMethod = "DecodeJumpTarget";
class FJ<bits<8> op, dag outs, dag ins, string asmstr, list<dag> pattern,
InstrItinClass itin>: Cpu0Inst<outs, ins, asmstr, pattern, itin, FrmJ>
{
bits<24> addr;
let Opcode = op;
let Inst{23-0} = addr;
}
After replacing the "$target" to "$addr", tblgen build successfully.
let isCall=1, hasDelaySlot=1 in {
//@JumpLink {
class JumpLink<bits<8> op, string instr_asm>:
- FJ<op, (outs), (ins calltarget:$target, variable_ops),
- !strconcat(instr_asm, "\t$target"), [(Cpu0JmpLink imm:$target)],
+ FJ<op, (outs), (ins calltarget:$addr, variable_ops),
+ !strconcat(instr_asm, "\t$addr"), [(Cpu0JmpLink imm:$addr)],
IIBranch> {
//#if CH >= CH10_1 2
let DecoderMethod = "DecodeJumpTarget";
Have you found this issue, or it's just a regression from the llvm project's evolution?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.