VxWorks 6.9 内核编程指导之读书笔记 -- C++开发

在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>

使用风河工具链

  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

    注意:-r4选项填充输入文件中包含的任何COMDAT段。

使用GNU工具链

  1. 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
  2. Munch the object file:
    nmppc hello.o | wtxtcl installDir/vxworks-6.x/host/src/hutils/munch.tcl
    -c ppc > ctdt.c
  3. 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
  4. 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值