Andes Workshop

It is currently Mon Oct 22, 2018 12:06 am

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Linking a binary object with gcc, objcopy related
PostPosted: Fri Mar 23, 2018 1:18 pm 
Offline

Joined: Mon Dec 12, 2016 5:07 pm
Posts: 18
1. Open a toolchain console.
2. Use
Quote:
dd if=/dev/urandom of=blob.bin bs=1 count=16
to generate a blob.bin file. You can use
Quote:
hexdump -C blob.bin
to check the content.
3. Use nds32le-mculib-objcopy to transform it to an object file.
Quote:
nds32le-mculib-objcopy -I binary -O elf32-nds32le -B n1h blob.bin blob-n1h.o
The part of the red color depends on which toolchain you use. The followings are the same and won't note any more.
Quote:
nds32le-mculib-readelf -h blob-n1h.o
will help you to examine what is generated. Take note on the Flags and we will explain it at the end of this article.
Then, you can link the blob.o with other .o files. For example:
Quote:
nds32le-muclib-gcc main.o blob.o -o mytest.o


==============================

The following command will show the architecture of the object file.
Quote:
nds32le-mculib-objdump -ft blob.o
blob-n1h.o: file format elf32-nds32le
architecture: n1h, flags 0x00000010:
HAS_SYMS
start address 0x00000000

SYMBOL TABLE:
00000000 l d .data 00000000 .data
00000000 g .data 00000000 _binary_blob_bin_start
00000010 g .data 00000000 _binary_blob_bin_end
00000010 g *ABS* 00000000 _binary_blob_bin_size

When you use different options on objcopy, it shows different architectures. You can use n1h_v3 or n1h_v3m depending on the toolchain you use.

In the following, I made 3 items. 1> generic compiled object main.o 2>blob-n1h.o generated by nds32le-mculib-objcopy with "-B n1h" option 3>blob-n1h-v3m.o generated by nds32le-mculib-objcopy with "-B n1h_v3m" option. "n1h" architecture is an Andes generic architecture.
Use "nds32le-mculib-readelf -h" to examine the header. You can see the values differences of the Flags. The Flags with 0 means it's a generic object that can link with any objects at link time by ignoring the every difference in the Flags field. So you can link main.o and blob-n1h.o. If you use blob-n1h-v3m.o with main.o, the Flags will fail with the ABI or object version checking. The messages you will get are like "ABI mismatch with previous modules" or " Older version of object file encountered, Please recompile with current tool chain" for example . For objcopy command, there are no options to modify the ABI and version fields.
Quote:
$ nds32le-elf-gcc blob-n1h-v3m.o src/demo/main.o -o mytest.o
/cygdrive/c/Andestech/AndeSight_STD_v310_Official/toolchains/nds32le-elf-mculib-v3/bin/../lib/gcc/nds32le-elf/4.9.4/../../../../nds32le-elf/bin/ld: blob-n1h-v3m.o: warning: Older version of object file encountered, Please recompile with current tool chain.
/cygdrive/c/Andestech/AndeSight_STD_v310_Official/toolchains/nds32le-elf-mculib-v3/bin/../lib/gcc/nds32le-elf/4.9.4/../../../../nds32le-elf/bin/ld: blob-n1h-v3m.o: error: ABI mismatch with previous modules.


Attachments:
objcopy_n1h_diff.png
objcopy_n1h_diff.png [ 31.32 KiB | Viewed 569 times ]
Top
 Profile Send private message E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group