符号
apktool d <APK_FILE>
# /etc/apt/apt.conf
Acquire::http::Proxy "http://10.90.50.122:8889";
Using awk to print all columns from the nth to the last
# Print all but the first column
awk '{$1=""; print substr($0,2)}' somefile
# Print all but the fisrt two columns
awk '{$1=$2=""; print substr($0,3)}' somefile
awk -F'[, ]' '{print $1 " " $2}'
awk '{sum+=$1} END {print sum}'
$# # not include command
$ miao.sh wang # $# is 1
same to array
${@:3:2} # from position 3, length 2
${@:3} # from position 3, to last
参考bash手册关于cd的说明
# 等价于cd $OLDPATH
cd -
CMD=(
"args"
"${OTHER_ARGS[@]}"
)
eval "${CMD[@]}" # "${CMD[*]}"
if test-commands; then
consequent-commands;
[elif more-test-commands; then
more-consequents;]
[else alternate-consequents;]
fi
set -o errexit
SO: find definition of bash func
shopt -s extdebug
declare -F <func>
shopt -u extdebug
COMMAND <<InputComesFromHERE
# ...
InputComesFromHERE
N=4
for i in {a..z}; do
(
# do your stuff here
) &
if [[ $(jobs -r -p | wc -l) -ge $N ]]; then
wait -n
fi
done
wait
echo all done
# see `help set`
set -x # turn on
set +x # turn off
while read line
do
echo "$line"
done < file
How do I test if a variable is a number in Bash?
re='^[0-9]+$'
if [[ $yournumber =~ $re ]]
then
echo "is a num!"
fi
set -o xtrace
echo ':i386:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfa\xff\xff:/usr/local/bin/qemu-i386:' >/proc/sys/fs/binfmt_misc/register
sudo ./scripts/qemu-binfmt-conf.sh --qemu-path /usr/local/bin/qemu-x86_64 --systemd x86_64
echo ':x64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00:\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-x86_64:' >/proc/sys/fs/binfmt_misc/register
cmake use CMakeCache.txt
If meet unexpected behavior,
clean all cmake generated files
-DCMAKE_EXPORT_COMPILE_COMMANDS=1
CMakeFiles/CMakeError.log
CMakeFiles/CMakeOutput.log
--progress=plain
docker ps -as
docker images -a
docker system prune
docker ps -aq | xargs docker rm
docker images -aq | xargs docker rmi
docker rm <containers>
docker rmi <images>
podman images | grep "^<none>" | awk '{print $3}' | xargs podman rmi
docker stop <containers>
podman build --network=host -t <tag>
podman unshare
podman image mount <image>
podman run --rm --network=host -it <image>
--cap-add=SYS_PTRACE
https://stackoverflow.com/questions/1423346
Noted: dd only take decimal number, 0x prefix does not work.
dd skip=<start> count=<size> if=<input> of=<output> bs=1
dd if=<INPUT/PATH> of=/dev/<OUTPUT> status=progress
df -h
du -sBM * | sort -n
exiftool -Title=<title> <file>
exiftool -Author=<author> <file>
http://www.figlet.org/examples.html
fc-list
fc-scan
repo: GH: google/fonts/ofl/
search: fonts.google.com
sudo grub-mkfont -s 36 -o /boot/grub/fonts/DejaVuSansMono.pf2 /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf
fc-list
vim /boot/grub/grub.cfg
otf2bdf -r 242 -p 36 /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf -o ~/Desktop/DejaVuSansMono.bdf
Increase qcow2 2GB
qemu-img resize <.qcow2> +2G
Inside FreeBSD
camcontrol reporbe ada0
# find out index
gpart show
gpart resize -i <index> ada0
growfs /
# edit /etc/rc.conf
linux_enable="YES"
service linux start
gcc -Q --help=target
No clobber, may segment fault! Just an example.
#include <stdio.h>
int a = 10;
int b = 20;
int result;
int main(void)
{
( "mov a, %eax\n\t"
asm"mov b, %ebx\n\t"
"add %ebx, %eax\n\t"
"mov %eax, result");
("the result is %d\n", result);
printfreturn 0;
}
#include <stdio.h>
int a = 10;
int b = 20;
int result;
int main(void)
{
( "mov a, %%eax\n\t"
asm"mov b, %%ebx\n\t"
"add %%ebx, %%eax\n\t"
"mov %%eax, result"
: /* no outputs*/
: /* no inputs */
: "eax", "ebx");
("the result is %d\n", result);
printfreturn 0;
}
2012.SO: preprocessor defined macros
gcc -dM -E - < /dev/null
touch bla.c && gcc -dM -E bla.c
gcc -static -Wl,-Ttext=0x1000 <Args>
bt
frame <bt num>
info frame <bt num>
info locals
Simulation Mode
# generate header from MyMemObject.py
scons build/ARM/params/MyMemObject.hh
output: src/doxygen/html
cd src
doxygen
gem5.opt configs/example/se.py --cmd <CMD>
# can use git update then
git clone --mirror <URL>
git config remote.origin.fetch "+refs/*:refs/*"
git config remote.origin.mirror true
列举remote的分支
# 无需联网
git branch -r [-l <patthern>]
# 需要联网
git remote show <remote>
git ls-remote <remote>
# 面对merge节点似乎有问题
git log -c -S'<string>' <file>
git log -c -G'<regex>' <file>
# 然后搜索
/<string>
git clone git://10.90.50.99/<REPO>
git clone -b <tag> --depth=1 <repo>
# root commit
git rebase -i --root
# non-root commit
git rebase -i <commits>
git daemon --base-path=/home/xieby1/Codes/ --export-all
git diff > <xxx.patch>
# simplified
git log --all --decorate --oneline --graph --simplify-by-decoration
# full
git log --all --decorate --oneline --graph
Scanning each input file stops upon first match.
Therefore, it is fast!
grep -l
sudo docker exec headscale headscale -n <NETWORK> nodes register --key <KEY>
tailscale up --force-reauth --reset
sudo docker exec -it headscale headscale nodes del -i <ID>
sudo docker exec headscale headscale --help
sudo tailscale --socket <PATH> up --login-server <URL>[:PORT]
fold/collapse/expand
<details>
<summary>Details</summary>
miao</details>
<span style="background: red; color: white; font-weight: bold;">
<div style="text-align:right; font-size:3em;">2022.04.12</div>
identify <image>
Poppler/Cairo import (Huge size)
<Ctrl><Shift>G # ungroup
! # invert selection
<Ctrl><Shift>R # resize canvas
Extensions->Text->Replace Font
# first time run
nix-shell -p bundler --run "bundle install"
# serve
nix-shell -p bundler -p jekyll --run "bundle exec jekyll serve -H 0.0.0.0 -P 4000"
ctrl+shift+m
make defconfig && make
include/config/kernel.release
make menuconfig: General setup -> Local version
make INSTALL_PATH=<path> install
make INSTALL_MOD_PATH=<path> modules_install
# 需要先编译
./scripts/clang-tools/gen_compile_commands.py
make ARCH=x86 COMPILED_SOURCE=1 cscope
由nm
生成,符号类型见man nm
/proc/kallsyms
System.map
系统调用表sys_call_table
ref: dmesg output to tty
x86上不可靠:输出不全,几次就关闭了
tty # `who am i` may not output
cat /proc/kmsg > <stdio dev file>
show info about a mod
modinfo <mod>
clang -S -emit-llvm <file.c> -o <file.ll>
clang -c -emit-llvm <file.c> -o <file.bc>
lli <file.ll/bc>
# a rule
target … : prerequisites …
recipe …
EXECUTABLES=$(patsubst %.cpp, %, $(wildcard *.cpp))
all: ${EXECUTABLES}
SO: How do I execute each command in a list?
define \n
endef
$(foreach x,${EXECUTABLES},rm ${x}${\n})
$(wildcard pictures/*.drawio)
foo bar biz &: baz boz
$^ > foo
echo $^ > bar
echo $^ > biz echo
include hashdeps.mk
combined.txt: $(call hash_deps,a.txt b.txt)
"Concatenating files"
echo $(call unhash_deps,$^) > $@ cat
%:%.c
$(CC) $< -o $@
foo bar biz &: baz boz
echo $^ > foo
echo $^ > bar
echo $^ > biz
$< # first
$^ # all
$(word 2,$^) # second
make -nd <target> | make2graph
# makefile2graph <target>
remake --targets
https://maven.apache.org/guides/mini/guide-proxies.html
settings>
<proxies>
<proxy>
<id>example-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy.example.com</host>
<port>8080</port>
<username>proxyuser</username>
<password>somepassword</password>
<nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
<proxy>
</proxies>
</settings> </
同名md和html html优先
host <domain name>
nmap 192.168.1.0/24
# /etc/netplan/50-cloud-init.yaml
network:
version: 2
wifis:
renderer: networkd
wlan0:
access-points:
<name>:
password: <...>
hidden: true
dhcp4: true
optional: true
# 列支持的语言
tesseract --list-langs
详细见ocrmypdf.md
ocr会将原pdf栅格化,
所以需要分离文本和图片
# 去除文本
gs -o notext.pdf -dFILTERTEXT \
<input.pdf>
-sDEVICE=pdfwrite # 运行ocr
ocrmypdf --force-ocr --output-type pdf \
$lang notext.pdf ocr.pdf
-l # 去除图片仅保留文本
gs -o textonly.pdf -dFILTERIMAGE \
-sDEVICE=pdfwrite ocr.pdf
-dFILTERVECTOR # 叠加文本
qpdf notext.pdf --overlay \
-- <output.pdf> textonly.pdf
pandoc --list-highlight-languages
pandoc -D <FORMAT>
--print-default-data-file=templates/styles.html
write ‘~’ to file home
parallel --tag ssh {1} ls {2}/Codes ::: myloongson55 myloongson56 myloongson57 myloongson58 :::: ./home
parallel --tag ssh {1} ls \\~/Codes ::: myloongson55 myloongson56 myloongson57 myloongson58
perldoc perlrun
perl -pe 's/(?<=foo)bar/test/g' file.txt
convert input1.jpg input2.jpg input3.jpg output.pdf
convert input.xxx -resize 100x200\! output.xxx
apk info -L <pkg>
dpkg-deb -c <package_name.deb>
dpkg-query -L <package_name>
apt-file list <package_name>
10.0.2.2
mount -t cifs -o user=miao%miao //10.0.2.4/qemu Host/
[qemu-sys] -m 16 -nographic -fda [file]
quickemu --display none --vm ~/Img/ubuntu-22.10.conf
# cat ~/Img/ubuntu-22.10/ubuntu-22.10.ports
ssh quickemu
./OpenCore-Boot.sh
ssh forward by useing emulated vlan
SO: center child divs inside parent div
:::{style="display:inline-block; text-align:left;"}
things here are all
left aligned
! :::
del: clear current
backspace: clear all
c: note canva
b: chalkboard
d: download drawings
x: previous color
y: next color
right click: eraser
Name | Effect |
---|---|
fade-out | Start visible, fade out |
fade-up | Slide up while fading in |
fade-down | Slide down while fading in |
fade-left | Slide left while fading in |
fade-right | Slide right while fading in |
fade-in-then-out | Fades in, then out on the next step |
fade-in-then-semi-out | Fades in, then to 50% on the next step |
semi-fade-out | Fade out to 50% |
Name | Effect |
---|---|
highlight-red | Turn text red |
highlight-green | Turn text green |
highlight-blue | Turn text blue |
highlight-current-red | Turn text red, then back to original on next step |
highlight-current-green | Turn text green, then back to original on next step |
highlight-current-blue | Turn text blue, then back to original on next step |
Name | Effect |
---|---|
grow | Scale up |
shrink | Scale down |
strike | Strike through |
<p class="fragment" data-fragment-index="3">Appears last</p>
<p class="fragment" data-fragment-index="1">Appears first</p>
<p class="fragment" data-fragment-index="2">Appears second</p>
Append ?print-pdf
to URL.
<style>nav {...}<style>
sudo route add -net 172.17.103.0 \
\
gw 10.90.50.254 \
netmask 255.255.255.0 \
metric 1000 dev enp9s0
sudo route del -net 172.17.103.0 \
gw 10.90.50.254netmask 255.255.255.0 \
dev enp9s0
rustup show
rustc --print target-list
rustup target add <TARGET>
cargo build --target=<TARGET> --release
scons -c
GH: barrier: Please make an Android client
# In this mode, adb (USB debugging) is not necessary
scrcpy --window-width 100 --window-height 100 --otg -s DEVICEID
man sed
[addr]X[options]
[addr]{X1[options]; X2[options]; ...}
POSIX.2 BREs
-print0
results separated by null char
find . -type f -print0 | \
xargs -0 sed -i 's/.../.../g'
if match return 1
else return 0
sed '/<pattern>/Q 1'
sed -z 's/\nwang\nmiao\n//g'
sed 's/\(.*\)miao/\1wang/g'
// command line:
// dot -Tsvg -O sixu.dot
digraph {
// attributes
/// graph
rankdir=BT;
/// subgraph
newrank=true;
style=filled;
//// color name: https://graphviz.org/doc/info/colors.html
color=whitesmoke;
/// node
node[
shape=box,
style="filled, solid",
color=black,
fillcolor=white,
];
/// edge
edge[
minlen=1,
//weight=1,
// If false, the edge is not used in ranking the nodes.
//constraint=true,
];
}
"22Apr12+" -> "22Apr12-" -> "22Apr12+";
subgraph cluster_22Apr12
{
x22Apr12_
}
{rank=same;
"22Apr12-";
x22Apr12_
}
{rank=same;
"22Apr12+";
}
ssh -L 8890:example.org:8889 -N -T username@remote_host
ssh -Y
sudo fallocate -l 4G /swapfile
# optional
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
man systemd.unit
man systemd.unit
~/.config/systemd/
systemctl --user status <service>
journalctl --user -u <service>
# sys
journalctl -f -u <service>
# user
journalctl --user -f -u <service>
# 例如列出list
systemctl list-units --type target
#Create the directory:
sudo mkdir /etc/systemd/system/getty@tty1.service.d
#Create file:
sudo vim /etc/systemd/system/getty@tty1.service.d/autologin.conf
#Insert:
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin YOURUSERNAMEHERE --noclear %I 38400 linux
[Unit]
Description=Swapon
[Install]
WantedBy=default.target multi-user.target
[Service]
ExecStart=swapon /swapfile
# NOTED: no ./ before dir !!!
tar czf bin.tar.gz <dir>
[[ $TERM != "screen" ]] && exec tmux
man tmux
: Description
Any number of tmux instances can
cnnect to the same session.
<C-b> " // vertical
<C-b> % // horizontal
wine regedit /?
https://github.com/okibcn/wslcompact
--shutdown
wsl
diskpartselect vdisk \
="C:\Users\<User>\AppData\Local\ \
file.UbuntuonWindows... \
Packages\CanonicalGroupLimited.vhdx"
\LocalState\ext4 compact vdisk
Alt-F2
r
Xephyr :2 -resizeable -dpi 48 -host-cursor
DISPLAY=:2 <command>
xrandr --output DP-1 --scale-from 2880x1800
# Stop flicker
xrandr --output eDP-1 --scale 0.9999x0.9999
x0vncserver -password <PSWD> -securitytypes=none -geometry 800x600+0+480 -FrameRate 10
xdg-mime query filetype <file>
xdg-mime query default <type>
yarn global add node_module
yarn global bin
C-S-f
Enter
S-Enter
clang
-I<PATH>
-D<VAR>
perl -e "print crypt('wjxby','xb');"
pdftk <file1.pdf …> cat output <output.pdf>
dgen <path>
https://github.com/brendangregg/FlameGraph
sudo perf record -g <cmd>
sudo perf script > out.perf
stackcollapse-perf.pl out.perf > out.folded
flamegraph.pl out.folded > out.svg
mov desktop file to
~/.config/autostart/
https://developer-old.gnome.org/desktop-entry-spec/
TODO: dash-to-dock? or original dock?
ctrl
+super
+<num>
gtk-launch <xxx.desktop>
# compile
gcc ... -gp
# run <file>
# show
gprof <file>
kitty +kitten ssh myserver
kitty +kitten ssh -J jump_server destination_server
# 获取package的名字
pkg-config --list-all | grep <xxx>
# 获取c编译、链接参数
pkg-config --cflags --libs <pkg>
pdftotext -noframes -i -q -p -c <pdf>
pdftotext -q <pdf>
ps -jHg <pid> # 进程子树
pstree -psal <pid> # 完整树
adduser xieby1
usermod -aG sudo xieby1
hold ctrl
+ shift
# 文本编码转换
iconv -f gb18030 -t utf-8 <output>
| xclip -selection clipboard
SE: Multiple arguments in shebang
#!/usr/bin/env -S cmd arg1 arg2 ...
sort -s -n -k 1,1
SO: Calibrate one touch one not
xinput --map-to-output $(xinput list --id-only "WingCoolTouch WingCoolTouch") DP-1
clang-format -style=llvm -dump-config > .clang-format
// clang-format off
...
// clang-format on
import pdb
pdb.set_trace()
dir()
vars()
<code needed to be ignored> # type: ignore
https://microsoft.github.io/pyright/#/configuration
# pyrightconfig.json
{
reportGeneralTypeIssues = false,
}
requirements.txt
E.g.
>= 2.8.1, == 2.8.* ; python_version < "2.7" requests [security]
chinese support compromise
use rsvg-convert
to convert
svg able to copy, support chinese
"svg.fonttype"] = "none" plt.rcParams[
:buffers " or
:ls " or
:files
:bdelete
" tab key works
:buffer <name>
vim -V9myVim.log
; open current file's dir
:E[xplore]
rm ~/.local/share/nvim/.netrwhist
c-v ; select block
g c-a
; insert below
:r!<cmd>
; insert above
:-r!<cmd>
; insert top
:0r!<cmd>
In select mode
u ; lower case
U ; upper case
# in netrw mode
%
" set
zf{motion} " :h motion.txt
" toggle
za
" range
:{range}fo[ld]
:set cursorline
ls <$VIMRUNTIME>/syntax/
:GenTocGFM
":n/v/imap
:map
:h inex
🐁 <leader>[
:echo $VIMRUNTIME
c-w _ ; max height
1c-w _ ;min height
c-w = ;same height
:on ; close others
c-w o ;same above
<$VIMRUNTIME>/filetype.vim
:set scrollbind
:set noscrollbind
it can control syntax and coc
set filetype=python
:set syntax=
; set
:set syntax=html
; get
:set syntax
set laststatus=2
:ju " 列出jumplist
<C-o> " 退
<C-i> " 进
; cs querytype
🐁 <C-\>[sgdcteFia]
重新加载
:!cscope -R
:cs reset
<leader>m " 标记/取消标记
{N}<leader>m " 给第N组添加标记词
{N}<leader>n " 取消第N组的标记
<leader>M " 显示标记颜色和标记词
🐁 <leader><F3> " 取消所有标记
ale支持的fix位于
autoload/ale/fix/registry.vim
所有fixer的调用脚本位于
autoload/ale/fixers/
; 🐁toggle
<F9>
:h :terminal
# exit temrinal mode
<C-\><C-N>
# enter temrinal mode
i
diff两个竖分buffers
; 分别在两个buffer里
:difft[his]
; 关闭,分别
:diffoff
let g:gitgutter_diff_base = ''
:GitGutterDiffOrig
" Diff against the index
:Gitsigns diffthis
" Diff against the last commit
:Gitsigns diffthis ~1
" obtain
do
" put
dp
和git相同的略。fugitive的特性:
:Git blame " blame整个文件
:Gedit " 跳转光标下到对应的object(某个版本的某个文件)
Gedit <refname>
enter " opon
o " horizon open
O " new tab open
<num>gt " switch tag
<leader>gm " 在popup窗口显示commit信息
:AnsiEsc
~/.local/share/nvim/config-local
:ConfigSource
:ConfigEdit
:ConfigTrust
:ConfigIgnore
trigger every time :w
,
or trigger manually
:call GitWipSave()
s ; forward
S ; backward
GH Issue: query.lua query: error at position #759
:TSUpdate
:TSUninstall all
; exit vim
home-manager switch
vim
:TSUpdate
:CocDisable
:CocEnable
:e
reload file is neccessary
:let b:coc_diagnostic_disable=1
:e
:h /\%c
\%23c Matches in a specific column.
\%<23c Matches before a specific column.
\%>23c Matches after a specific column.
\%.c Matches at the cursor column.
\%<.c Matches before the cursor column.
\%>.c Matches after the cursor column.
# list all DIR/FILE
zellij setup --check
<nix channel url>/store-path.xz
e.g. https://mirror.tuna.tsinghua.edu.cn/nix-channels/nixos-21.11/store-paths.xz
refers to Discourse: Is it possible to query the binary cache?
nix path-info \
\
--store https://cache.nixos.org/ '<nixpkgs>' \
-f \
--argstr system x86_64-linux <pkgs-name>
# import may need sudo
nix-store --import/--export
How to use a local directory as a nix binary cache?
--no-check-sigs \
nix copy --to <output/path> </nixstore/path>
-env -i <output/path> nix
nix-store --verify [--check-contents] [--repair]
nix-store -qR
sudo nix-copy-closure --from <user@ssh> <path>
nix-channel --option tarball-ttl 0 --update [<channel>]
man nix.conf
nix show-config
nixpkgs manual: Global configuration
/etc/nixosconfiguration.nix
{
nixpkgs.config = {
allowUnfree = true;
};
}
~/.config/nixpkgs/config.nix
{
allowUnfree = true;
}
Nix manual: Proxy Environment Variables
/etc/systemd/system/nix-daemon.service.d/override.conf
nix-shell
. $stdenv/setup
nix-build -K <drv>
nix-build '<nixpkgs>' -A xxx
nix-store --query --referrers <nix-path>
nix-store --query --references <nix-path>
nix eval --expr "<EXPR>"
~/.nix-profile/share/applications
(import <nixpkgs/nixos> {}).config; sysconfig =
sudo nix-collect-garbage -d
nix-collect-garbage -d
ls -l /nix/var/nix/gcroots/auto
ls -l /nix/var/nix/gcroots/per-user/<user>
nix-build '<nixpkgs>' -A <pkg>
SE:
Disabling the security hardening options for a nix-shell
environment
export NIX_HARDENING_ENABLE=""
echo "use nix" >> .envrc
direnv allow
pkgs/desktops/gnome/extensions/extensions.json
nix-prefetch-url
nix-prefetch-url --unpack \
<owner>/
https://github.com/<repo>/archive/<rev>.tar.gz
nix-prefetch-url --unpack
nix-hash --type sha256 \
--base32 <file> --flat
# man nix3-path-info
# closure-size
nix path-info -Sh <path>
nix show-derivation <.drv>
import <nixpkgs> {} pkgs =
sudo nix-env -p /nix/var/nix/profiles/system --list-generations
sudo nix-collect-garbage -d
# User Generations (Home-Manager)
nix-collect-garbage -d
nix-instantiate --eval -E "<path>"
nix-version --hash
sshd-start
home-manager option <OPTION>
bash nixos-option <OPTION>
possible dependency types and examples
D type | D’s host | D’s target |
---|---|---|
build → * | build | (none) |
build → build | build | build |
build → host | build | host |
build → target | build | target |
host → * | host | (none) |
host → host | host | host |
host → target | host | target |
target → * | target | (none) |
target → target | target | target |
possible dependency types and examples
TODO: simplify
g++ links against the host platform’s glibc C library, which is a “host→ ” dependency with a triple of (bar, bar, ). Since it is a library, not a compiler, it has no “target”.
Since g++ is written in C, the gcc compiler used to compile it is a “build→ host” dependency of g++ with a triple of (foo, foo, bar). This compiler runs on the build platform and emits code for the host platform.
gcc links against the build platform’s glibc C library, which is a “build→ ” dependency with a triple of (foo, foo, ). Since it is a library, not a compiler, it has no “target”.
This gcc is itself compiled by an earlier copy of gcc. This earlier copy of gcc is a “build→ build” dependency of g++ with a triple of (foo, foo, foo). This “early gcc” runs on the build platform and emits code for the build platform.
g++ is bundled with libgcc, which includes a collection of target-machine routines for exception handling and software floating point emulation. libgcc would be a “target→ ” dependency with triple (foo, baz, ), because it consists of machine code which gets linked against the output of the compiler that we are building. It is a library, not a compiler, so it has no target of its own.
libgcc is written in C and compiled with gcc. The gcc that compiles it will be a “build→ target” dependency with triple (foo, foo, baz). It gets compiled and run at g++-build-time (on platform foo), but must emit code for the baz-platform.
g++ allows inline assembler code, so it depends on access to a copy of the gas assembler. This would be a “host→ target” dependency with triple (foo, bar, baz).
g++ (and gcc) include a library libgccjit.so, which wrap the compiler in a library to create a just-in-time compiler. In nixpkgs, this library is in the libgccjit package; if C++ required that programs have access to a JIT, g++ would need to add a “target→ target” dependency for libgccjit with triple (foo, baz, baz). This would ensure that the compiler ships with a copy of libgccjit which both executes on and generates code for the baz-platform.
If g++ itself linked against libgccjit.so (for example, to allow compile-time-evaluated C++ expressions), then the libgccjit package used to provide this functionality would be a “host→ host” dependency of g++: it is code which runs on the host and emits code for execution on the host.
host → target | attribute name | offset |
---|---|---|
build –> build | depsBuildBuild | -1, -1 |
build –> host | nativeBuildInputs | -1, 0 |
build –> target | depsBuildTarget | -1, 1 |
host –> host | depsHostHost | 0, 0 |
host –> target | buildInputs | 0, 1 |
target –> target | depsTargetTarget | 1, 1 |
pkgs/build-support/fetch.*/
pkgs/stdenv/generic/make-derivation.nix
''
# escape ${
''${bash_var}
# escape ''
'''
''
<path>
, like <nixpkgs>
, is
path
listed in env NIX_PATH
# foobar.nix
{lib, withFoo ? "bar", ...}:
{# ...}
# configuration.nix
args@{ ... }:
{imports = [(
import ./foobar.nix (args // { withFoo = "baz"; })
)];}
sudo nix-env -p /nix/var/nix/profiles/system --list-generations
nix-shell '<nixpkgs>' -A <pkg>
use nix <path>
if [[ -z "$IN_NIX_SHELL" ]]; then
use nix <path>
fi
patchShebangs <path>
Inspired by cursed.nix
My tests show, as long as there are arguments in nix-shell, the interp mode of nix-shell is not triggered!
Therefore, I change -v
to --keep miao
Why it works?
#!/usr/bin/env -S nix-shell --keep miao
# nix built-in
nix bundle
# github 465 start
nix-bundle
# all dependencies
nix-store --query --requisites </nix/store/path>
## or
nix-store --query -R </nix/store/path>
# nested tree
nix-store --query --tree </nix/store/path>
# only immediate dependencies
nix-store --query --references </nix/store/path>
nix-tree </nix/store/path>
nix-shell -E "with import <nixpkgs> {}; callPackage ./default.nix {}"
lib.lowPrio <pkg>
nix-locate 'bin/hello'
pkgs/top-level/python-packages.nix
pkgs/development/python-modules/
pkgs/development/interpreters/python/mk-python-derivation.nix
pyobject3
pkgs/tools/typesetting/tex/texlive/pkgs.nix
SO: How to produce static executable on NixOS?
pkgs.glibc.static
pkgs.zlib.static
? :
:e <expr>
refers to nix repl home.nix config
import <home-manager/modules> { configuration = ~/.config/nixpkgs/home.nix; pkgs = import <nixpkgs> {}; } hm =
Support -static
nix-shell -p pkgsCross.musl64.stdenv.cc
x86_64-unknown-linux-musl-gcc -static hello.c
Nix currently use musl-gcc
nix-shell -p pkgsStatic.stdenv.cc
x86_64-unknown-linux-musl-gcc -static hello.c
nix-shell -p pkgsCross.aarch64-multiplatform.stdenv.cc
aarch64-unknown-linux-gnu-gcc
2021.armv8.pdf: C1.2.4: Table C1-1
cond | Mnem | Mean(int) | Mean(flp) | Cond flags |
---|---|---|---|---|
0000 | EQ | == | == | Z==1 |
0001 | NE | != | != or unordered | Z==0 |
0010 | CS or HS | Carry set | >=, or unordered | C==1 |
0011 | CC or LO | Carry clear | < | C==0 |
0100 | MI | Minus, negative | < | N==1 |
0101 | PL | Plus, positive or zero | >=, or unordered | N==0 |
0110 | VS | Overflow | Unordered | V==1 |
0111 | VC | No overflow | Ordered | V==0 |
1000 | HI | Unsigned higher | >, or unordered | C==1&&Z==0 |
1001 | LS | Unsigned lower or same | <= | !(C==1&&Z==0) |
1010 | GE | Signed >= | >= | N==V |
1011 | LT | Signed < | <, or unordered | N!=V |
1100 | GT | Signed > | > | Z==0&&N==V |
1101 | LE | Signed <= | <=, or unordered | !(Z==0&&N==V) |
1110 | AL | Always | Always | Any |
1111 | NV | Always | Always | Any |
2021.armv8.pdf: B1.2.2 2021.armv8.pdf: C5.2.9
// gdb: p cpsr # Current Program Status Register
// 6 333222 | N: Negative
// 3 ... 210987 ... 0 | Z: Zero
// RES0 NZCV RES0 | C: Carry (unsigned)
// | V: Overflow (signed)
//
mrs x1, NZCV // get NZCV
msr NZCV, x1 // set NZCV
2021.armv8.pdf:
arch/arm64/mm/hugetlbpage.c
Page Size | CONT PTE | PMD | CONT PMD | PUD |
---|---|---|---|---|
4K | 64K | 2M | 32M | 1G |
16K | 2M | 32M | 1G | |
64K | 2M | 512M | 16G |
2021.armv8.pdf
B2.5.2
EL | Description | Typical |
---|---|---|
EL0 | unprivileged execution | Applications |
EL1 | privileged execution | OS kernel |
EL2 | virtualization | Hypervisor |
EL3 | switching between Secure/Non-secure state | Secure monitor |
📑 Arm Architecture Reference Manual Armv8
[x1]
[x1, #12]
[x1, #12]!
// x1+=12, addr=x1[x1], #12
// addr=x1, x1+=12arm linux only use bottom 40 bits of a pointer
pointer[63:40] = PAC(pointer[39:40], key, modifier)
AUT(pointer[63:40], pointer[39:40], key, modifier)
five separate keys:
ARMv8
Non-temporal load and store pair
Hint mem system no cache, typically in streaming data.
E.g. an atomic subtract
1f404: ldaxr w1, [x0]
1f408: sub w2, w1, #0x1
1f40c: stxr w3, w2, [x0]
1f410: cbnz w3, 1f404
cannot be nested,
as each hardware thread supports only one monitor.
https://en.wikichip.org/wiki/risc-v/registers
C | Reg | ABI | Description | |
---|---|---|---|---|
- | x0 | zero | hardwired zero | - |
- | x1 | ra | return addr | r |
- | x2 | sp | stack pointer | e |
- | x3 | gp | global pointer | - |
- | x4 | tp | thread pointer | - |
- | x5-7 | t0-2 | temp reg 0-2 | r |
0 | x8 | s0/fp | saved reg 0/frame pointer | e |
1 | x9 | s1 | saved reg 1 | e |
2-3 | x10-11 | a0-1 | func arg 0-1/ret val 0-1 | r |
4-7 | x12-15 | a2-5 | func arg 2-7 | r |
- | x16-17 | a6-7 | func arg 6-7 | r |
- | x18-27 | s2-11 | saved reg 2-11 | e |
- | x28-31 | t3-t6 | temp reg 3-6 | r |
2022.intel64_opt.pdf
搜索Cache Parameters可搜到各个架构的cache参数
x86_64-abi.pdf: Figure 3.4
x86-64-linux callee saved regs:
%rbx, %rbp, %r12-r15
2018.intel64.pdf: Volume 1: Appendix B: Table B-1
CC | subcode | status |
---|---|---|
O | 0000 | OF |
NO | 0001 | !OF |
C, B, NAE | 0010 | CF |
NB, AE | 0011 | !CF |
E, Z | 0100 | ZF |
NE, NZ | 0101 | !ZF |
BE, NA | 0110 | CF|ZF |
NBE, A | 0111 | !(CF|ZF) |
S | 1000 | SF |
NS | 1001 | !SF |
P, PE | 1010 | PF |
NP, PO | 1011 | !PF |
L, NGE | 1100 | SF!=OF |
NL, GE | 1101 | SF==OF |
LE, NG | 1110 | (SF!=OF)|ZF |
NLE, G | 1111 | !((SF!=OF)|ZF) |
2020.amd64.pdf: 3.1.4
// 11 | Overflow Direction
// 10..76.4.2.0 | Sign Zero
// OD SZ A P C | Auxiliary Parity
// | Carry
pushf // get
popf // set
2020.amd64.pdf: 3.1.2
2020.amd64.pdf: Figure 1-2
2018.intel64.pdf: Figure 2-1
Name | B | Description |
---|---|---|
Legacy Prefix | ≤5 | optional |
REX | 1 | 64-bit mode only |
Escape | 2 | optional |
Opcode | 1 | |
ModRM | 1 | optional |
SIB | 1 | optional |
Displacement | ||
Immediate |
2020.amd64.pdf: Figure 1-2
Name | B | Description |
---|---|---|
Legacy Prefix | ≤4 | optional |
VEX/XOP | 1 | |
RXB.map+Select | 1 | not for VEX C5 |
W.vvvv.L.pp | 1 | not for VEX C5 |
R.vvvv.L.pp | 1 | for VEX C5 |
Opcode | 1 | |
ModRM | 1 | optional |
SIB | 1 | optional |
Displacement | 1,2,4,8 | 8B Disp & 8B Imm mutual exclusive |
Immediate | 1,2,4,8 | 8B Disp & 8B Imm mutual exclusive |
2020.amd64.pdf: Table 5-1
Mode | PAE | PSE | PDPE.PS | PDE.PS | Page Size | Max VA | Max PA |
---|---|---|---|---|---|---|---|
Long | 1 | - | 0 | 0 | 4KB | 64bit | 52bit |
Long | 1 | - | 0 | 1 | 2MB | 64bit | 52bit |
Long | 1 | - | 1 | - | 1GB | 64bit | 52bit |
Legacy | 1 | - | 0 | 0 | 4KB | 32bit | 52bit |
Legacy | 1 | - | 0 | 1 | 2MB | 32bit | 52bit |
Legacy | 0 | 0 | 0 | - | 4KB | 32bit | 32bit |
Legacy | 0 | 1 | 0 | 0 | 4kB | 32bit | 32bit |
Legacy | 0 | 1 | 0 | 1 | 4MB | 32bit | 40bit |
2020.amd64.pdf: Volume 3: 2.5.1
ADDPD xmm1, xmm2/mem128
──┬── ──┬─ ───────┬───
Mnemonic ─┘ │ │
└────────┐ │
First Source Operand ─┘ │
and Destination Operand │
│
Second Source Operand ─────┘
2020.amd64.pdf: Volume 3: 2.5.2
2018.intel64.pdf: Volume 2: 3.1.1.1
2020.amd64.pdf: Table 1-10
ModRM = mod[2] : reg[3] : r/m[3]
M: MMX, X: XMM, Y: YMM
b | reg | r/m (mod=11b) | r/m (mod!=11b) |
---|---|---|---|
000 | rAX,M0,X0,Y0 | rAX,M0,X0,Y0 | [rAX] |
001 | rCX,M1,X1,Y1 | rCX,M1,X1,Y1 | [rCX] |
010 | rDX,M2,X2,Y2 | rDX,M2,X2,Y2 | [rDX] |
011 | rBX,M3,X3,Y3 | rBX,M3,X3,Y3 | [rBX] |
100 | AH,rSP,M4,X4,Y4 | AH,rSP,M4,X4,Y4 | SIB |
101 | CH,rBP,M5,X5,Y5 | CH,rBP,M5,X5,Y5 | [rBP]* |
110 | DH,rSI,M6,X6,Y6 | DH,rSI,M6,X6,Y6 | [rSI] |
111 | BH,rDI,M7,X7,Y7 | BH,rDI,M7,X7,Y7 | [rDI] |
2020.amd64.pdf: Table 1-12
SIB = scale[2] : index[3] : base[3]
scale = 2^(SIB.scale)
b | index | base |
---|---|---|
000 | [rAX] | [rAX] |
001 | [rCX] | [rCX] |
010 | [rDX] | [rDX] |
011 | [rBX] | [rBX] |
100 | (none)1 | [rSP] |
101 | [rBP] | [rBP], (none)2 |
110 | [rSI] | DH, [rSI] |
111 | [rDI] | BH, [rDI] |
2018.intel64.pdf: Table 3-5
Default Segment Selection
Ref Type | Reg | Default Rule |
---|---|---|
Inst | CS | All inst fetches |
Stack | SS | All pushes & pops |
Local Data | DS | All data, except relative to stack or string destination |
Destination Strings | ES | Destination string inst |
2018.intel64.pdf: Table 3-5
Offset =
Base + (Index * Scale) + Displacement
+- -+ +- -+ +-+ +------+
|eax| |eax| |1| |None |
|ebx| |ebx| |2| |8-bit |
|ecx| |ecx| |4| |16-bit|
|edx| + |edx| * |8| + |32-bit|
|esp| |ebp| | | | |
|ebp| |esi| | | | |
|esi| |edi| | | | |
|edi| | | | | | |
+- -+ +---+ +-+ +------+
Read and write from user space
Addressing
__seg_fs
, __seg_gs
mov %fs:offset, %reg
,
mov %reg, %fs:offset