<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><style>body { line-height: 1.5; }blockquote { margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em; }body { font-size: 10.5pt; font-family: 微软雅黑; color: rgb(0, 0, 0); line-height: 1.5; }</style></head><body>
<div><span></span>This problem drives me crazy. </div><div>I can use dlopen to load my object file, this part works fine. When I loaded the object file, it showed something like: </div><div>> <span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">handle: 0x2a9bb0 loaded</span></div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">And then I could get the address of this handle via dlsym, </span></div><div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">> call = dlsym(handle, "hello_world");</span></div><span style="color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);"><span style="white-space: pre;">> </span>if (call == NULL) {<br><span style="white-space: pre;">>       </span>printf("dlsym failed: symbol hello_world not found\n");<br><span style="white-space: pre;">>   </span>return 1;<br><span style="white-space: pre;">> </span>}</span></div><div><span style="color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">> </span><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">printf("address: %x\n", call);</span></div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">it said like: </span></div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">> </span><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">address: 2aa3a1</span></div><div><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5;">But, when I continued to jump to the entry point of call, the system crashed. </span><span style="background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-height: 1.5; white-space: pre;">      </span></div><div><span style="color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);"><span style="white-space: pre;">> </span>call_ret = call(2, call_1);<br><span style="white-space: pre;">> </span>if (call_ret != 2) {<br><span style="white-space: pre;">> </span><span style="white-space: pre;"> </span>printf("dlsym call failed: ret value bad\n");<br><span style="white-space: pre;">> </span><span style="white-space: pre;">       </span>return 1;<br>> }</span></div><div><span style="color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">My platform is Zedboard.</span></div><div><span style="color: rgb(0, 0, 0); background-color: rgba(0, 0, 0, 0);">My code is just like the dl01 example, would someone help me with this, thanks a lot.</span></div><div><br><div><br></div>
<div><br></div><hr style="width: 210px; height: 1px;" color="#b5c4df" size="1" align="left">
<div><span><div style="MARGIN: 10px; FONT-FAMILY: verdana; FONT-SIZE: 10pt"><div><font color="#0000ff">Best wishes,</font></div><div><font color="#0000ff">Tim Tian</font></div><div><font color="#0000ff">xuelin.tian@qkmtech.com</font></div></div></span></div>
<blockquote style="margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em;"><div> </div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm"><div style="PADDING-RIGHT: 8px; PADDING-LEFT: 8px; FONT-SIZE: 12px;FONT-FAMILY:tahoma;COLOR:#000000; BACKGROUND: #efefef; PADDING-BOTTOM: 8px; PADDING-TOP: 8px"><div><b>From:</b> <a href="mailto:ppisa4lists@pikron.com">Pavel Pisa</a></div><div><b>Date:</b> 2016-08-26 20:01</div><div><b>To:</b> <a href="mailto:users@rtems.org">users</a></div><div><b>CC:</b> <a href="mailto:xuelin.tian@qkmtech.com">xuelin.tian@qkmtech.com</a>; <a href="mailto:chrisj@rtems.org">Chris Johns</a></div><div><b>Subject:</b> Re: Simple question about RTL</div></div></div><div><div>Hello Tim Tian,</div>
<div> </div>
<div> </div>
<div>On Friday 26 of August 2016 10:24:55 xuelin.tian@qkmtech.com wrote:</div>
<div>> I follow the instructions which Pavel Pisa posted online.</div>
<div>> https://lists.rtems.org/pipermail/devel/2016-July/015683.html</div>
<div>> But, when I go to the "prelink generation" step, which is</div>
<div>> "arm-rtems4.11-gcc ${CFLAGS1} -Wl,--gc-sections init.o rootfs_tarfile.o -lm</div>
<div>> -o appdl.prelink", some error came up, #/.../ld: failed to merge target</div>
<div>> specific data of file init.o</div>
<div> </div>
<div>You should post the messages before this final error.</div>
<div> </div>
<div>I expect that your problem is that object file generated by</div>
<div>objdump has incompatible ARM ABI compiled in (even that there</div>
<div>is in the fact no code in binary data)</div>
<div> </div>
<div>You can try to skip check in the final link by adding</div>
<div> </div>
<div>   -Wl,--accept-unknown-input-arch</div>
<div> </div>
<div>to GCC command line or </div>
<div> </div>
<div>   --accept-unknown-input-arch</div>
<div> </div>
<div>if bare LD is used.</div>
<div> </div>
<div>My sequence is</div>
<div> </div>
<div>  arm-rtems4.12-ld -r --accept-unknown-input-arch -b binary -o rootfs_tarfile.o.tmp rootfs_tarfile</div>
<div>  arm-rtems4.12-objcopy --rename-section .data=.rodata,alloc,load,readonly,data,contents rootfs_tarfile.o.tmp rootfs_tarfile.o</div>
<div> </div>
<div>Do you use the output of the second step for final linking. The first step of binary</div>
<div>to object conversion (rootfs_tarfile.o.tmp) is holds default architecture</div>
<div>variant flags which is incompatible with most other ARM targets.</div>
<div> </div>
<div>The second step with objcopy removes these sections.</div>
<div> </div>
<div>If you use bigendian ARM target then default is little endian</div>
<div>and this cannot be merged at all. The arm-rtems4.12-ld -r requires</div>
<div>to add "-EB" option. I oversside that in OMK hackish way for now</div>
<div>and need to solve that better</div>
<div> </div>
<div>$(2).o: $(2)</div>
<div>        @$(QUIET_CMD_ECHO) "  TARFILE $$@"</div>
<div>-       $(Q) $(LD) -r --accept-unknown-input-arch -b binary -o $$@.tmp $$^</div>
<div>+       $(Q) $(LD) -EB -r --accept-unknown-input-arch -b binary -o $$@.tmp $$^</div>
<div>        $(Q) $(OBJCOPY) --rename-section .data=.rodata,alloc,load,readonly,data,contents $$@.tmp $$@</div>
<div> </div>
<div> </div>
<div>Best wishes,</div>
<div> </div>
<div>                Pavel</div>
<div> </div>
<div> </div>
<div>> #/.../ld: warning: cannot find entry symbol _start; defaulting to</div>
<div>> 0000000000008000 #collect2: error: ld returned 1 exit status</div>
<div>></div>
<div>> And he did not use rtems-ld to generate any file, so I got a little</div>
<div>> confused. Any idea?</div>
<div>></div>
<div>> Later, I also tried to use rtems-ld to link init.o and rootfs_tarfile.o,</div>
<div>> and it said: #resolver:resolving: undefines, unresolved: 1</div>
<div>> #resolver:resolve: |- rtems</div>
<div>> #error: undefines: symbol not found: rtems</div>
<div>> Here, I just want to know what '-b' the base kernel is, an object file</div>
<div>> (after compile before link), or an .exe (after statically link)? Thanks.</div>
<div> </div>
<div>></div>
<div>></div>
<div>> Best wishes,</div>
<div>> Tim Tian</div>
<div>> xuelin.tian@qkmtech.com</div>
<div>></div>
<div>> From: Chris Johns</div>
<div>> Date: 2016-08-25 13:30</div>
<div>> To: xuelin.tian@qkmtech.com; users@rtems.org</div>
<div>> Subject: Re: Simple question about RTL</div>
<div>></div>
<div>> On 25/08/2016 1:02 PM, xuelin.tian@qkmtech.com wrote:</div>
<div>> > Hi Chris,</div>
<div>> > thanks for you reply. I'm trying to understand the concept here, and</div>
<div>> > some points are still confusing me.</div>
<div>> > In general, linking process should happen before applications taking</div>
<div>> > control of CPU, which means the OS should handle the linking process.</div>
<div>></div>
<div>> The RTL provides a run-time link editor which allows you to load code</div>
<div>> with-in your running application. Libdl is the link editor. It is you or</div>
<div>> your code that tells it what to do.</div>
<div>></div>
<div>> > In</div>
<div>> > RTEMS, the Init task should take care of this, am I right?</div>
<div>></div>
<div>> The Init task is your 'main' so this is your code. You are free to</div>
<div>> structure how you manage this just like any other part of your application.</div>
<div>></div>
<div>> > Now, for example, I have one base kernel and one tar file. My base</div>
<div>> > kernel is running on my target (ZedBoard), and how can I load the tar</div>
<div>> > file into memory using shell command via Jtag?</div>
<div>></div>
<div>> For an engineering development environment I would enable networking</div>
<div>> using libbsd and then NFS mount an exported disk from a host on the</div>
<div>> network. I would place the ELF object files where you can see them from</div>
<div>> the Zedboard and then use the RTL command to load the code.</div>
<div>></div>
<div>> Chris</div>
</div></blockquote>
</div></body></html>