在C++模块被下载到VxWorks内核之前,由于历史原因,它必须经历一个额外的步骤,称为munching。Munching执行以下任务
对静态对象的初始化支持
确保对所有的静态对象按顺序调用正确的构造和析构函数。
对应风河的编译器,自动填充COMDAT段;对应GNU编译器,自动填充linkonce段。
Munching必须在下载之前,编译之后执行。
Munching的例子
对于每一个工具链,下面的例子编译了一个C++应用程序源码hello.cpp,在.o上运行munch,编译产生ctdt.c文件,并连接应用程序和ctdt.o产生可可下载的模块,hello.out。
<em><strong>使用风河工具链</strong> </em>
1. Compile the source code:
$ dcc -tPPC604FH:vxworks61 -Xlocal-data-area-static-only -XO \
-IinstallDir/vxworks-6.x/target/h -DCPU=PPC32 -DTOOL_FAMILY=diab -DTOOL=diab \
-D_WRS_KERNEL -c hello.cpp
2. Munch the object file:
$ ddump -Ng hello.o | tclsh \
installDir/vxworks-6.x/host/resource/hutils/tcl/munch.tcl -c ppc > ctdt.c
3. Compile the munch output:
$ dcc -tPPC604FH:vxworks61 -Xlocal-data-area-static-only -XO \
-IinstallDir/vxworks-6.x/target/h -DCPU=PPC32 -DTOOL_FAMILY=diab -DTOOL=diab \
-D_WRS_KERNEL -c ctdt.c
4. Link the original object file with the munched object file to create a
downloadable module:
$ dld -tPPC604FH:vxworks61 -X -r4 -o hello.out hello.o ctdt.o<br><br><em><strong>注意:-r4选项填充输入文件中包含的任何COMDAT段。</strong></em>
使用风河工具链
- Compile the source code:
$ dcc -tPPC604FH:vxworks61 -Xlocal-data-area-static-only -XO
-IinstallDir/vxworks-6.x/target/h -DCPU=PPC32 -DTOOL_FAMILY=diab -DTOOL=diab
-D_WRS_KERNEL -c hello.cpp - Munch the object file:
$ ddump -Ng hello.o | tclsh
installDir/vxworks-6.x/host/resource/hutils/tcl/munch.tcl -c ppc > ctdt.c - Compile the munch output:
$ dcc -tPPC604FH:vxworks61 -Xlocal-data-area-static-only -XO
-IinstallDir/vxworks-6.x/target/h -DCPU=PPC32 -DTOOL_FAMILY=diab -DTOOL=diab
-D_WRS_KERNEL -c ctdt.c - Link the original object file with the munched object file to create a
downloadable module:
$ dld -tPPC604FH:vxworks61 -X -r4 -o hello.out hello.o ctdt.o
注意:-r4选项填充输入文件中包含的任何COMDAT段。
使用GNU工具链
- Compile the source code:
ccppc -mcpu=604 -mstrict-align -O2 -fno-builtin
-IinstallDir/vxworks-6.x/target/h
-DCPU=PPC604 -DTOOL_FAMILY=gnu -DTOOL=gnu -c hello.cpp - Munch the object file:
nmppc hello.o | wtxtcl installDir/vxworks-6.x/host/src/hutils/munch.tcl
-c ppc > ctdt.c - Compile the munch output:
ccppc -mcpu=604 -mstrict-align -fdollars-in-identifiers -O2
-fno-builtin -IinstallDir/vxworks-6.x/target/h
-DCPU=PPC604 -DTOOL_FAMILY=gnu -DTOOL=gnu -c ctdt.c - Link the original object file with the munched object file to create a
downloadable module:
ccppc -r -nostdlib -Wl,-X
-T installDir/vxworks-6.x/target/h/tool/gnu/ldscripts/link.OUT
-o hello.out hello.o ctdt.o
注意:VxWorks内核对象加载器并不直接支持linkonce段。相反,在加载之前,linkonce段必须被合并和填充到标准的text和data段。-T选项用来填充任何包含的linkonce段。
使用通用的Makefile规则
如果使用makefile,则可以编写简单的munch规则(定义适当的CPU和TOOL),可以在支持GUN和风河工具链。
CPU = PPC604
TOOL = gnu
TGT_DIR = $(WIND_BASE)/target
include $(TGT_DIR)/h/make/defs.bsp
default : hello.out
%.o : %.cpp
$(CXX) $(C++FLAGS) -c $<
%.out : %.o
$(NM) $.o | $(MUNCH) > ctdt.c
$(CC) $(CFLAGS) $(OPTION_DOLLAR_SYMBOLS) -c ctdt.c
$(LD_PARTIAL) $(LD_PARTIAL_LAST_FLAGS) -o $@ $.o ctdt.o
munching、下载和连接之后,静态构造和析构将被调用。
参考目录
https://www.cnblogs.com/C-Sharp2/p/5912537.html