每周学习摘要01(23/09/18-23/09/24)

电控

stm32

OpenOCD SWD 时钟频率设置

adapter speed 100

这样可以设置swd时钟频率,而且要放在stm32f4x.cpu configure -rtos chibios前面才能起作用,否则会被Override

Exception handlers

Interrupt Service :Interrupts IRQ0 to IRQ81 are the exceptions handled by ISRs.
Routines (ISRs) :Fault handlers Hard fault, memory management fault, usage fault, bus fault are fault
exceptions handled by the fault handlers.
System handlers: NMI, PendSV, SVCall SysTick, and the fault exceptions are all
system exceptions that are handled by system handlers.
For other information, please refer to PM0214(or sth else) at Section 2.3.3

System Handler priority settings

System handler priority registers (SHPRx) on page 233

OpenOCD 无法使用SWD烧录(包括Stlink和CMSIS-DAP)

在USB DFU模式下利用STM32CubeProgrammer清除flash

ChibiOS

名词解释

oip: ch_os_instance pointer
oicp: ch_os_instance_config pointer

校内学习

linux嵌入式

软件

实时显示按键信息

keyviz

Windows 启动文件夹

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

Windows Explorer崩溃解决方法

[原创]Win10 explorer资源管理器崩溃解决方法

Windows 11下VMware 虚拟机很卡

同样的虚拟机,在Windwos10下就很流畅,但是在Windows11下非常卡,请用管理员权限运行VMWareWorkstation 来源

[vmware]解决虚拟机不能拖拽传递文件的方法

安装vmtools

1.首先安装open-vm-tools和open-vm-tools-desktop两个包
2.其次在虚拟机settings页面options分页找到Guest Isolation,开启Enable drag and drop和Enable copy and paste
3.虚拟机内linux桌面需要用x.org启动而不是Wayland(貌似还未支持)

设置Xorg为default display server(optional)

gdm设置

修改gdm的config

sudo vim /etc/gdm3/custom.conf

WaylandEnable这一行取消注释来关闭Wayland

# Uncomment the line below to force the login screen to use Xorg
WaylandEnable=false

[u-boot解读之基于全志V3s]01顶层Makefile解析

1.xxx_defconf的解析

在573行

config: scripts_basic outputmakefile FORCE
    $(Q)$(MAKE) $(build)=scripts/kconfig $@

%config: scripts_basic outputmakefile FORCE
    $(Q)$(MAKE) $(build)=scripts/kconfig $@

可以看到,当我们执行 make LicheePi_Zero_defconfig时,会触发该规则.
可以看到后面有两个prerequisites:scripts_basic,outputmakefile,以及一个FORCE
这个FORCE是为了每次触发该规则都能执行这条命令,可以参考www.gnu.org:Force-Targets

1.1FORCE目标

在2483行:

PHONY += FORCE
FORCE:

# Declare the contents of the PHONY variable as phony.  We keep that
# information in a variable so we can use it in if_changed and friends.
.PHONY: $(PHONY)

可知FORCE是一个伪目标

1.2$(Q)是个什么?

在100行可以看到

ifeq ($(KBUILD_VERBOSE),1)
  quiet =
  Q =
else
  quiet=quiet_
  Q = @
endif

如果未设置KBUILD_VERBOSE环境变量为1,就会隐藏执行的指令
因此我们可以在分析脚本时,设置该环境变量来看具体执行了什么
在67行也有相应的原理分析:

# Beautify output
# ---------------------------------------------------------------------------
#
# Normally, we echo the whole command before executing it. By making
# that echo $($(quiet)$(cmd)), we now have the possibility to set
# $(quiet) to choose other forms of output instead, e.g.
#
#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
#
# If $(quiet) is empty, the whole command will be printed.
# If it is set to "quiet_", only the short version will be printed.
# If it is set to "silent_", nothing will be printed at all, since
# the variable $(silent_cmd_cc_o_c) doesn't exist.
#
# A simple variant is to prefix commands with $(Q) - that's useful
# for commands that shall be hidden in non-verbose mode.
#
#   $(Q)ln $@ :<
#
# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
# If KBUILD_VERBOSE equals 1 then the above command is displayed.
#
# To put more focus on warnings, be less verbose as default
# Use 'make V=1' to see the full commands

1.3scripts_basic目标

PHONY += scripts_basic
scripts_basic:
    $(Q)$(MAKE) $(build)=scripts/basic
    $(Q)rm -f .tmp_quiet_recordmcount

生成scripts/basic下的工具fixdep

1.4outputmakefile目标

PHONY += outputmakefile
# outputmakefile generates a Makefile in the output directory, if using a
# separate output directory. This allows convenient use of make in the
# output directory.
outputmakefile:
ifneq ($(KBUILD_SRC),)
    $(Q)ln -fsn $(srctree) source
    $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
endif

如果KBUILD_SRC不为空,在该路径自动生成Makefile(这个规则用不到)

综上所述,%config规则将传入的LicheePi_Zero_defconfig传给scripts/kconfig的Makefile并执行

1.5 kconfig下的Menuconfig

来到第95行

%_defconfig: $(obj)/conf
    $(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)

这调用了刚才在Kconfig下由conf.c生成的工具conf,来生成
完整命令如下:

scripts/kconfig/conf  --defconfig=arch/../configs/LicheePi_Zero_defconfig Kconfig

至于$SRCARCH又是什么
位于第九行

# Added for U-Boot
#  Linux has defconfig files in arch/$(SRCARCH)/configs/,
#  on the other hand, U-Boot does in configs/.
#  Set SRCARCH to .. fake this Makefile.
SRCARCH := ..

原来u-boot项目是仿照linux仓库的结构的,但是u-boot不需要把defconfig放在每个arch目录下

conf.c中生成defconfig

第664行

    case defconfig:
        conf_set_all_new_symbols(def_default);

然后conf_set_all_new_symbols在scripts/kconfig/confdata文件中定义,感兴趣的读者可以继续深入,但由于篇幅限制,仅用知道整个过程是往u-boot顶级目录里写入.config文件

2.直接运行make命令

2.1第一个目标

第147行

# That's our default target when none is given on the command line
PHONY := _all
_all:

然后221行

# If building an external module we do not care about the all: rule
# but instead _all depend on modules
PHONY += all
ifeq ($(KBUILD_EXTMOD),)
_all: all
else
_all: modules
endif

默认依赖all目标
之后是1112行

# Timestamp file to make sure that binman always runs
.binman_stamp: $(INPUTS-y) FORCE
ifeq ($(CONFIG_BINMAN),y)
    $(call if_changed,binman)
endif
    @touch $@

all: .binman_stamp

all依赖.binman_stamp,又间接依赖了$(INPUTS-y)
INPUTS-y是什么呢

2.2 INPUTS-y目标

未完待续

[u-boot解读之基于全志V3s]00序言

序言

现在开始我要开一个新坑,也就是对u-boot项目的解读
一开始初入嵌入式开发,常常会对一些编译操作一知半解,比如

  • 为什么要配置defconfig?
  • xx文件是怎么生成的
  • 最终编译出来的文件包含了哪些源文件(Sc文件)
    等等
    为了提高日后的开发效率,我们需要透过现象看本质
    因此,我会从顶层Makefile入手来剖析整个项目,顺便进行学习

笔者将基于u-boot仓库主线:2023.10-rc4,git commit hash 为252592214,
基于Allwinner公司的V3s芯片进行分析,建议读者购买一块v3s开发板,可以从闲鱼购买,只需要二三十块钱

05:10:28 ztn@ZTN-PC u-boot ±|master ✗|→ git log -a
252592214f79d8206c3cf0056a8827a0010214e0 (grafted, HEAD -> master, origin/master, origin/HEAD)          ├─────────────────────────────────────────
Author: Tom Rini <trini@konsulko.com>                                                                          │04:33:37 ztn@ZTN-PC u-boot ±|master ✗|→
Date:   Sat Sep 9 09:33:02 2023 -0400

探究ndk中llvm与默认llvm的差别

使用ndk中的clang工具链(clang+ld):

03:00:36 ztn@ztn-laptop2 ~ → /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -target aarch64-linux-android21 main.c -###
Android (7019983 based on r365631c3) clang version 9.0.9 (https://android.googlesource.com/toolchain/llvm-project a2a1e703c0edb03ba29944e529ccbf457742737b) (based on LLVM 9.0.9svn)
Target: aarch64-unknown-linux-android21
Thread model: posix
InstalledDir: /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin
 "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang" "-cc1" "-triple" "aarch64-unknown-linux-android21" "-emit-obj" "-mrelax-all" "-mnoexecstack" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mthread-model" "posix" "-mdisable-fp-elim" "-masm-verbose" "-mconstructor-aliases" "-fuse-init-array" "-target-cpu" "generic" "-target-feature" "+neon" "-target-abi" "aapcs" "-mllvm" "-aarch64-fix-cortex-a53-835769=1" "-fallow-half-arguments-and-returns" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/local/include" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/aarch64-linux-android" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include" "-fdebug-compilation-dir" "/home/ztn" "-ferror-limit" "19" "-fmessage-length" "0" "-fno-signed-char" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "/tmp/main-f62791.o" "-x" "c" "main.c"
 "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld" "-pie" "-z" "noexecstack" "-EL" "--fix-cortex-a53-843419" "--warn-shared-textrel" "-z" "now" "-z" "relro" "-z" "max-page-size=4096" "--hash-style=both" "--enable-new-dtags" "--eh-frame-hdr" "-m" "aarch64linux" "-dynamic-linker" "/system/bin/linker64" "-o" "a.out" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtbegin_dynamic.o" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/lib/linux/aarch64" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib/../lib64" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib" "/tmp/main-f62791.o" "-lgcc" "-ldl" "-lc" "-lgcc" "-ldl" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtend_android.o"

利用llvm14.0 clang-default编译+链接指令:

04:05:47 ztn@ztn-laptop2 ~ → clang -target aarch64-linux-android21 main.c --sysroot=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot -###
Ubuntu clang version 14.0.0-1ubuntu1
Target: aarch64-unknown-linux-android21
Thread model: posix
InstalledDir: /usr/bin
 "/usr/lib/llvm-14/bin/clang" "-cc1" "-triple" "aarch64-unknown-linux-android21" "-emit-obj" "-mrelax-all" "--mrelax-relocations" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=non-leaf" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8a" "-target-feature" "+fix-cortex-a53-835769" "-target-abi" "aapcs" "-fallow-half-arguments-and-returns" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-fcoverage-compilation-dir=/home/ztn" "-resource-dir" "/usr/lib/llvm-14/lib/clang/14.0.0" "-isysroot" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot" "-internal-isystem" "/usr/lib/llvm-14/lib/clang/14.0.0/include" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" "-fdebug-compilation-dir=/home/ztn" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/main-f0839f.o" "-x" "c" "main.c"
 "/usr/bin/ld" "--sysroot=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot" "-pie" "-EL" "--fix-cortex-a53-843419" "--warn-shared-textrel" "-z" "now" "-z" "relro" "-z" "max-page-size=4096" "--hash-style=gnu" "--hash-style=both" "--build-id" "--enable-new-dtags" "--eh-frame-hdr" "-m" "aarch64linux" "-dynamic-linker" "/system/bin/linker64" "-o" "a.out" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21/crtbegin_dynamic.o" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib" "/tmp/main-f0839f.o" "-lgcc" "-ldl" "-lc" "-lgcc" "-ldl" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21/crtend_android.o"

利用llvm-default中的clang编译(命令也来自default)+ndk中的ld链接(命令来自ndk中的ld):

04:13:36 ztn@ztn-laptop2 ~ → "/usr/lib/llvm-14/bin/clang" "-cc1" "-triple" "aarch64-unknown-linux-android21" "-emit-obj" "-mrelax-all" "--mrelax-relocations" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=non-leaf" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8a" "-target-feature" "+fix-cortex-a53-835769" "-target-abi" "aapcs" "-fallow-half-arguments-and-returns" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-fcoverage-compilation-dir=/home/ztn" "-resource-dir" "/usr/lib/llvm-14/lib/clang/14.0.0" "-isysroot" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot" "-internal-isystem" "/usr/lib/llvm-14/lib/clang/14.0.0/include" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" "-fdebug-compilation-dir=/home/ztn" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/main.o" "-x" "c" "main.c"
04:13:38 ztn@ztn-laptop2 ~ → nm /tmp/ma
main-dc2fc4.o  main-f62791.o  main.o         
04:13:38 ztn@ztn-laptop2 ~ → nm /tmp/main.o 
0000000000000000 r $d.1
0000000000000000 n $d.2
0000000000000000 r $d.3
0000000000000000 t $x.0
0000000000000000 T main
                 U printf
04:13:48 ztn@ztn-laptop2 ~ → "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld" "-pie" "-z" "noexecstack" "-EL" "--fix-cortex-a53-843419" "--warn-shared-textrel" "-z" "now" "-z" "relro" "-z" "max-page-size=4096" "--hash-style=both" "--enable-new-dtags" "--eh-frame-hdr" "-m" "aarch64linux" "-dynamic-linker" "/system/bin/linker64" "-o" "b.out" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtbegin_dynamic.o" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/lib/linux/aarch64" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib/../lib64" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib" "/tmp/main.o" "-lgcc" "-ldl" "-lc" "-lgcc" "-ldl" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtend_android.o"

在android上运行b.out()成功(termux)

采用ld.lld链接(复制最前面的链接参数)

04:30:06 ztn@ztn-laptop2 ~ → ld.lld "-pie" "-z" "noexecstack" "-EL" "--fix-cortex-a53-843419" "--warn-shared-textrel" "-z" "now" "-z" "relro" "-z" "max-page-size=4096" "--hash-style=both" "--enable-new-dtags" "--eh-frame-hdr" "-m" "aarch64linux" "-dynamic-linker" "/system/bin/linker64" "-o" "c.out" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtbegin_dynamic.o" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/lib/linux/aarch64" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib/../lib64" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib" "/tmp/main.o" "-lgcc" "-ldl" "-lc" "-lgcc" "-ldl" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtend_android.o"
04:30:34 ztn@ztn-laptop2 ~ → nm c.out 

成功执行

直接调用clang driver

直接用default llvm-clang 加上sysroot 和 -L,调用驱动器来编译(绕过NDK),貌似clang是根据target来判断怎么找文件的,具体路径好像是硬编码进了llvm项目。
在这个里面有写what-makes-clang-look-in-subdirectories-of-the-include-path:
Compiler drivers know where to tell the compiler (or actually the preprocessor) where to look for header files, usually by offsetting from the directory containing the driver executable, and this is hard-coded in the driver. It's generally undesirable to tell the driver to look in other subdirectories automatically, as this will very often result in very hard to track down bugs. In other words you want to specify the directories explicitly with -I.

clang --target=aarch64-linux-android21 -fno-addrsig -fuse-ld="E:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\aarch64-linux-android\\bin\\ld" --sysroot=E:\AndroidSDK\android-ndk-r20b\toolchains\llvm\prebuilt\windows\sysroot "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\lib\\clang\\8.0.7\\lib\\linux\\aarch64" "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\bin/../lib/gcc/aarch64-linux-android/4.9.x" "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib/../lib64" "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\bin/../sysroot/usr/lib/aarch64-linux-android/21" "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\bin/../sysroot/usr/lib/aarch64-linux-android" "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib" "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\bin/../sysroot/usr/lib" main.c

NDK的clang不同于llvm

用cmake构建AndroidManifest同级目录下的项目后(使用Ninja构建)

CMakeFiles/main.dir/build.make 下找到编译命令:

09:37:06 ztn@ztn-laptop2 app ±|master ✗|→ tree CMakeFiles
CMakeFiles
├── 3.22.1
│   ├── CMakeCCompiler.cmake
│   ├── CMakeCXXCompiler.cmake
│   ├── CMakeDetermineCompilerABI_C.bin
│   ├── CMakeDetermineCompilerABI_CXX.bin
│   └── CMakeSystem.cmake
├── cmake.check_cache
├── CMakeDirectoryInformation.cmake
├── CMakeOutput.log
├── CMakeTmp
├── main.dir
│   ├── build.make
│   ├── cmake_clean.cmake
│   ├── compiler_depend.make
│   ├── compiler_depend.ts
│   ├── DependInfo.cmake
│   ├── depend.make
│   ├── flags.make
│   ├── link.txt
│   ├── progress.make
│   └── src
│       └── main
│           └── cpp
│               ├── main.cpp.o
│               └── main.cpp.o.d
├── Makefile2
├── Makefile.cmake
├── progress.marks
└── TargetDirectories.txt

6 directories, 23 files
09:37:17 ztn@ztn-laptop2 app ±|master ✗|→ 

CMakeFiles/main.dir/src/main/cpp/main.cpp.o: CMakeFiles/main.dir/flags.make
CMakeFiles/main.dir/src/main/cpp/main.cpp.o: src/main/cpp/main.cpp
CMakeFiles/main.dir/src/main/cpp/main.cpp.o: CMakeFiles/main.dir/compiler_depend.ts
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/ztn/androidffmpeg5.0-demo/app/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building CXX object CMakeFiles/main.dir/src/main/cpp/main.cpp.o"
        /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -MD -MT CMakeFiles/main.dir/src/main/cpp/main.cpp.o -MF CMakeFiles/main.dir/src/main/cpp/main.cpp.o.d -o CMakeFiles/main.dir/src/main/cpp/main.cpp.o -c /home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp

CMakeFiles/main.dir/src/main/cpp/main.cpp.i: cmake_force
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/main.dir/src/main/cpp/main.cpp.i"
        /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp > CMakeFiles/main.dir/src/main/cpp/main.cpp.i

CMakeFiles/main.dir/src/main/cpp/main.cpp.s: cmake_force
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/main.dir/src/main/cpp/main.cpp.s"
        /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp -o CMakeFiles/main.dir/src/main/cpp/main.cpp.s

提取后并采用 -###参数查看clang具体命令

09:24:38 ztn@ztn-laptop2 app ±|master ✗|→ /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot $CXX_DEFINES $CXX_INCLUDES $CXX_FLAGS -MD -MT CMakeFiles/main.dir/src/main/cpp/main.cpp.o -MF CMakeFiles/main.dir/src/main/cpp/main.cpp.o.d -o CMakeFiles/main.dir/src/main/cpp/main.cpp.o -c /home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp -###
Android (7019983 based on r365631c3) clang version 9.0.9 (https://android.googlesource.com/toolchain/llvm-project a2a1e703c0edb03ba29944e529ccbf457742737b) (based on LLVM 9.0.9svn)
Target: aarch64-none-linux-android21
Thread model: posix
InstalledDir: /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin
 "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++" "-cc1" "-triple" "aarch64-none-linux-android21" "-emit-obj" "-mrelax-all" "-mnoexecstack" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" "posix" "-mdisable-fp-elim" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "generic" "-target-feature" "+neon" "-target-abi" "aapcs" "-mllvm" "-aarch64-fix-cortex-a53-835769=1" "-fallow-half-arguments-and-returns" "-dwarf-column-info" "-debug-info-kind=limited" "-dwarf-version=4" "-debugger-tuning=gdb" "-ffunction-sections" "-fdata-sections" "-coverage-notes-file" "/home/ztn/androidffmpeg5.0-demo/app/CMakeFiles/main.dir/src/main/cpp/main.cpp.gcno" "-resource-dir" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9" "-dependency-file" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o.d" "-sys-header-deps" "-MT" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o" "-D" "main_EXPORTS" "-I" "/home/ztn/androidffmpeg5.0-demo/app/soLib/arm64-v8a/include" "-D" "ANDROID" "-D" "_FORTIFY_SOURCE=2" "-isysroot" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" "-Wformat" "-Werror=format-security" "-fdeprecated-macro" "-fdebug-compilation-dir" "/home/ztn/androidffmpeg5.0-demo/app" "-ferror-limit" "19" "-fmessage-length" "0" "-stack-protector" "2" "-fno-signed-char" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o" "-x" "c++" "/home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp"
09:24:49 ztn@ztn-laptop2 app ±|master ✗|→ "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++" "-cc1" "-triple" "aarch64-none-linux-android21" "-emit-obj" "-mrelax-all" "-mnoexecstack" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" "posix" "-mdisable-fp-elim" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "generic" "-target-feature" "+neon" "-target-abi" "aapcs" "-mllvm" "-aarch64-fix-cortex-a53-835769=1" "-fallow-half-arguments-and-returns" "-dwarf-column-info" "-debug-info-kind=limited" "-dwarf-version=4" "-debugger-tuning=gdb" "-ffunction-sections" "-fdata-sections" "-coverage-notes-file" "/home/ztn/androidffmpeg5.0-demo/app/CMakeFiles/main.dir/src/main/cpp/main.cpp.gcno" "-resource-dir" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9" "-dependency-file" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o.d" "-sys-header-deps" "-MT" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o" "-D" "main_EXPORTS" "-I" "/home/ztn/androidffmpeg5.0-demo/app/soLib/arm64-v8a/include" "-D" "ANDROID" "-D" "_FORTIFY_SOURCE=2" "-isysroot" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" "-Wformat" "-Werror=format-security" "-fdeprecated-macro" "-fdebug-compilation-dir" "/home/ztn/androidffmpeg5.0-demo/app" "-ferror-limit" "19" "-fmessage-length" "0" "-stack-protector" "2" "-fno-signed-char" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o" "-x" "c++" "/home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp"
09:24:56 ztn@ztn-laptop2 app ±|master ✗|→ clang++ "-cc1" "-triple" "aarch64-none-linux-android21" "-emit-obj" "-mrelax-all" "-mnoexecstack" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" "posix" "-mdisable-fp-elim" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "generic" "-target-feature" "+neon" "-target-abi" "aapcs" "-mllvm" "-aarch64-fix-cortex-a53-835769=1" "-fallow-half-arguments-and-returns" "-dwarf-column-info" "-debug-info-kind=limited" "-dwarf-version=4" "-debugger-tuning=gdb" "-ffunction-sections" "-fdata-sections" "-coverage-notes-file" "/home/ztn/androidffmpeg5.0-demo/app/CMakeFiles/main.dir/src/main/cpp/main.cpp.gcno" "-resource-dir" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9" "-dependency-file" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o.d" "-sys-header-deps" "-MT" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o" "-D" "main_EXPORTS" "-I" "/home/ztn/androidffmpeg5.0-demo/app/soLib/arm64-v8a/include" "-D" "ANDROID" "-D" "_FORTIFY_SOURCE=2" "-isysroot" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" "-Wformat" "-Werror=format-security" "-fdeprecated-macro" "-fdebug-compilation-dir" "/home/ztn/androidffmpeg5.0-demo/app" "-ferror-limit" "19" "-fmessage-length" "0" "-stack-protector" "2" "-fno-signed-char" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o" "-x" "c++" "/home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp"
error: unknown argument: '-mdisable-fp-elim'
error: unknown argument: '-masm-verbose'
error: unknown argument: '-munwind-tables'
error: unknown argument: '-fuse-init-array'
error: unknown argument: '-dwarf-column-info'
error: unknown argument: '-fmessage-length'
error: unknown argument: '-fdiagnostics-show-option'
09:25:11 ztn@ztn-laptop2 app ±|master ✗|→ 

可以看到,从官网下载的LLVM-CLANG工具链没有一些由NDK中clang工具链支持的编译器选项,故谷歌NDK是修改过的一条工具链,不过LLVM main stream 貌似直接支持 arm-cortex-m
这里是具体规格和信息
Supported Devices
LLVM Toolchain Technical-Specifications