<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Here’s a simple example. Note I’m combining two .o files with ld -r into a relocatable. I want to stick to this approach (which matches what’s done on vxWorks) until we’ve done some testing between the vxWorks and RTEMS versions. Lots of scripts, etc. The way the RTEMS RTL loads this both .LC0 format strings will be “BAR %s\n”. I’ll read-up on ELF but the “Num” field appears to be what would make those .LC0 easily unique.<div class=""><br class=""></div><div class=""><div class="">Zynq dufault@gen6 fubar]$ cat foo.c</div><div class="">#include <stdio.h></div><div class=""><br class=""></div><div class="">extern void foo(void);</div><div class="">void foo(void)</div><div class="">{</div><div class=""> printf("FOO %s\n", "Foo 1");</div><div class="">}</div><div class="">Zynq dufault@gen6 fubar]$ cat bar.c</div><div class="">#include <stdio.h></div><div class=""><br class=""></div><div class="">extern void bar(void);</div><div class="">void bar(void)</div><div class="">{</div><div class=""> printf("BAR %s\n", "Bar 1");</div><div class="">}</div><div class="">Zynq dufault@gen6 fubar]$ arm-rtems5-gcc -march=armv7-a -mthumb -c foo.c</div><div class="">Zynq dufault@gen6 fubar]$ arm-rtems5-gcc -march=armv7-a -mthumb -c bar.c</div><div class="">Zynq dufault@gen6 fubar]$ arm-rtems5-ld -r -o fubar bar.o foo.o</div><div class="">Zynq dufault@gen6 fubar]$ arm-rtems5-readelf -s fubar</div><div class=""><br class=""></div><div class="">Symbol table '.symtab' contains 20 entries:</div><div class=""> Num: Value Size Type Bind Vis Ndx Name</div><div class=""> 0: 00000000 0 NOTYPE LOCAL DEFAULT UND </div><div class=""> 1: 00000000 0 SECTION LOCAL DEFAULT 1 </div><div class=""> 2: 00000000 0 SECTION LOCAL DEFAULT 3 </div><div class=""> 3: 00000000 0 SECTION LOCAL DEFAULT 4 </div><div class=""> 4: 00000000 0 SECTION LOCAL DEFAULT 5 </div><div class=""> 5: 00000000 0 SECTION LOCAL DEFAULT 6 </div><div class=""> 6: 00000000 0 SECTION LOCAL DEFAULT 7 </div><div class=""> 7: 00000000 0 FILE LOCAL DEFAULT ABS bar.c</div><div class=""> 8: 00000000 0 NOTYPE LOCAL DEFAULT 3 $d</div><div class=""> 9: 00000000 0 NOTYPE LOCAL DEFAULT 3 .LC0</div><div class=""> 10: 00000008 0 NOTYPE LOCAL DEFAULT 3 .LC1</div><div class=""> 11: 00000000 0 NOTYPE LOCAL DEFAULT 1 $t</div><div class=""> 12: 00000000 0 FILE LOCAL DEFAULT ABS foo.c</div><div class=""> 13: 00000010 0 NOTYPE LOCAL DEFAULT 3 $d</div><div class=""> 14: 00000010 0 NOTYPE LOCAL DEFAULT 3 .LC0</div><div class=""> 15: 00000018 0 NOTYPE LOCAL DEFAULT 3 .LC1</div><div class=""> 16: 0000001c 0 NOTYPE LOCAL DEFAULT 1 $t</div><div class=""> 17: 00000000 0 NOTYPE GLOBAL DEFAULT UND printf</div><div class=""> 18: 0000001d 28 FUNC GLOBAL DEFAULT 1 foo</div><div class=""> 19: 00000001 28 FUNC GLOBAL DEFAULT 1 bar</div><div class="">Zynq dufault@gen6 fubar]$ arm-rtems5-objdump --disassemble --source fubar</div><div class=""><div class=""><br class=""></div><div class="">fubar: file format elf32-littlearm</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Disassembly of section .text:</div><div class=""><br class=""></div><div class="">00000000 <bar>:</div><div class=""> 0:<span class="Apple-tab-span" style="white-space:pre"> </span>b580 <span class="Apple-tab-span" style="white-space:pre"> </span>push<span class="Apple-tab-span" style="white-space:pre"> </span>{r7, lr}</div><div class=""> 2:<span class="Apple-tab-span" style="white-space:pre"> </span>af00 <span class="Apple-tab-span" style="white-space:pre"> </span>add<span class="Apple-tab-span" style="white-space:pre"> </span>r7, sp, #0</div><div class=""> 4:<span class="Apple-tab-span" style="white-space:pre"> </span>f240 0100 <span class="Apple-tab-span" style="white-space:pre"> </span>movw<span class="Apple-tab-span" style="white-space:pre"> </span>r1, #0</div><div class=""> 8:<span class="Apple-tab-span" style="white-space:pre"> </span>f2c0 0100 <span class="Apple-tab-span" style="white-space:pre"> </span>movt<span class="Apple-tab-span" style="white-space:pre"> </span>r1, #0</div><div class=""> c:<span class="Apple-tab-span" style="white-space:pre"> </span>f240 0000 <span class="Apple-tab-span" style="white-space:pre"> </span>movw<span class="Apple-tab-span" style="white-space:pre"> </span>r0, #0</div><div class=""> 10:<span class="Apple-tab-span" style="white-space:pre"> </span>f2c0 0000 <span class="Apple-tab-span" style="white-space:pre"> </span>movt<span class="Apple-tab-span" style="white-space:pre"> </span>r0, #0</div><div class=""> 14:<span class="Apple-tab-span" style="white-space:pre"> </span>f7ff fffe <span class="Apple-tab-span" style="white-space:pre"> </span>bl<span class="Apple-tab-span" style="white-space:pre"> </span>0 <printf></div><div class=""> 18:<span class="Apple-tab-span" style="white-space:pre"> </span>bf00 <span class="Apple-tab-span" style="white-space:pre"> </span>nop</div><div class=""> 1a:<span class="Apple-tab-span" style="white-space:pre"> </span>bd80 <span class="Apple-tab-span" style="white-space:pre"> </span>pop<span class="Apple-tab-span" style="white-space:pre"> </span>{r7, pc}</div><div class=""><br class=""></div><div class="">0000001c <foo>:</div><div class=""> 1c:<span class="Apple-tab-span" style="white-space:pre"> </span>b580 <span class="Apple-tab-span" style="white-space:pre"> </span>push<span class="Apple-tab-span" style="white-space:pre"> </span>{r7, lr}</div><div class=""> 1e:<span class="Apple-tab-span" style="white-space:pre"> </span>af00 <span class="Apple-tab-span" style="white-space:pre"> </span>add<span class="Apple-tab-span" style="white-space:pre"> </span>r7, sp, #0</div><div class=""> 20:<span class="Apple-tab-span" style="white-space:pre"> </span>f240 0100 <span class="Apple-tab-span" style="white-space:pre"> </span>movw<span class="Apple-tab-span" style="white-space:pre"> </span>r1, #0</div><div class=""> 24:<span class="Apple-tab-span" style="white-space:pre"> </span>f2c0 0100 <span class="Apple-tab-span" style="white-space:pre"> </span>movt<span class="Apple-tab-span" style="white-space:pre"> </span>r1, #0</div><div class=""> 28:<span class="Apple-tab-span" style="white-space:pre"> </span>f240 0000 <span class="Apple-tab-span" style="white-space:pre"> </span>movw<span class="Apple-tab-span" style="white-space:pre"> </span>r0, #0</div><div class=""> 2c:<span class="Apple-tab-span" style="white-space:pre"> </span>f2c0 0000 <span class="Apple-tab-span" style="white-space:pre"> </span>movt<span class="Apple-tab-span" style="white-space:pre"> </span>r0, #0</div><div class=""> 30:<span class="Apple-tab-span" style="white-space:pre"> </span>f7ff fffe <span class="Apple-tab-span" style="white-space:pre"> </span>bl<span class="Apple-tab-span" style="white-space:pre"> </span>0 <printf></div><div class=""> 34:<span class="Apple-tab-span" style="white-space:pre"> </span>bf00 <span class="Apple-tab-span" style="white-space:pre"> </span>nop</div><div class=""> 36:<span class="Apple-tab-span" style="white-space:pre"> </span>bd80 <span class="Apple-tab-span" style="white-space:pre"> </span>pop<span class="Apple-tab-span" style="white-space:pre"> </span>{r7, pc}</div><div class="">Zynq dufault@gen6 fubar]$ </div></div><div class=""><br class=""></div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Apr 25, 2019, at 18:02 , Chris Johns <<a href="mailto:chrisj@rtems.org" class="">chrisj@rtems.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On 26/4/19 2:04 am, <a href="mailto:dufault@hda.com" class="">dufault@hda.com</a> wrote:<br class=""><blockquote type="cite" class="">In a given object file for "NOTYPE LOCAL” entries in a data segment with zero<br class="">size that don’t start with ‘$’ could you append text based on the Num field for<br class="">the rtems_rtl_obj symbol lookup in cpukit/libdl/rtl-sym.c? Right now it’s a<br class="">linear lookup on e.g. “.LC2” and stops at the first hit. I haven’t checked that<br class="">consumers of the lookup can generate the correct name, that is, always have the<br class="">“Num” field value.<br class=""></blockquote><br class="">I would like to understand at the ELF level what is happening before considering<br class="">solutions. As I indicated in my other email if the symbols are local and in<br class="">different sections it could be something in the handling of the relocation<br class="">records for a section that needs to consider the symbol section used for local<br class="">symbols. If the symbols are in the same section and match then I would question<br class="">why `ld` is doing this.<br class=""><br class=""><blockquote type="cite" class=""><br class="">You’d wind up with mangled lookups such as:<br class=""><br class=""> 22: 0000002c 0 NOTYPE LOCAL DEFAULT 3 .LC2.Num22<br class=""> 44: 0000013c 0 NOTYPE LOCAL DEFAULT 3 .LC2.Num44<br class=""><br class=""> This is from one of my relocatable files grepping for NOTYPE LOCAL. I’ve<br class="">verified large files also work.<br class=""></blockquote><br class="">This means the local symbol table now has different entries. How do you know<br class="">which one a relocation record is pointing too?<br class=""><br class="">Chris<br class=""><br class=""><blockquote type="cite" class=""> Num: Value Size Type Bind Vis Ndx Name<br class=""> 0: 00000000 0 NOTYPE LOCAL DEFAULT UND <br class=""> 14: 00000000 0 NOTYPE LOCAL DEFAULT 3 $d<br class=""> 15: 00000000 0 NOTYPE LOCAL DEFAULT 4 $d<br class=""> 17: 00000000 0 NOTYPE LOCAL DEFAULT 6 $d<br class=""> 18: 00000000 2048 NOTYPE LOCAL DEFAULT 6 env_entries<br class=""> 20: 00000800 4 NOTYPE LOCAL DEFAULT 6 env_initialized<br class=""> 21: 00000008 0 NOTYPE LOCAL DEFAULT 3 .LC1<br class=""> 22: 0000002c 0 NOTYPE LOCAL DEFAULT 3 .LC2<br class=""> 23: 00000030 0 NOTYPE LOCAL DEFAULT 3 .LC3<br class=""> 25: 00000000 0 NOTYPE LOCAL DEFAULT 1 $t<br class=""> 28: 00000050 0 NOTYPE LOCAL DEFAULT 3 .LC4<br class=""> 29: 00000058 0 NOTYPE LOCAL DEFAULT 3 .LC5<br class=""> 30: 00000080 0 NOTYPE LOCAL DEFAULT 3 .LC6<br class=""> 32: 00000094 0 NOTYPE LOCAL DEFAULT 3 .LC7<br class=""> 33: 000000c4 0 NOTYPE LOCAL DEFAULT 3 .LC8<br class=""> 34: 000000cc 0 NOTYPE LOCAL DEFAULT 3 .LC9<br class=""> 35: 000000f4 0 NOTYPE LOCAL DEFAULT 3 .LC10<br class=""> 37: 00000130 0 NOTYPE LOCAL DEFAULT 3 $d<br class=""> 38: 0000000c 0 NOTYPE LOCAL DEFAULT 4 $d<br class=""> 40: 00000804 0 NOTYPE LOCAL DEFAULT 6 $d<br class=""> 41: 00000d14 520 NOTYPE LOCAL DEFAULT 6 putenv_trace_ptrs<br class=""> 42: 00000690 0 NOTYPE LOCAL DEFAULT 1 $t<br class=""> 43: 00000138 0 NOTYPE LOCAL DEFAULT 3 .LC1<br class=""> 44: 0000013c 0 NOTYPE LOCAL DEFAULT 3 .LC2 <br class=""> 45: 0000014c 0 NOTYPE LOCAL DEFAULT 3 .LC3<br class=""> 47: 00000164 0 NOTYPE LOCAL DEFAULT 3 .LC4<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Apr 25, 2019, at 07:56 , Peter Dufault <<a href="mailto:dufault@hda.com" class="">dufault@hda.com</a><br class=""><<a href="mailto:dufault@hda.com" class="">mailto:dufault@hda.com</a>>> wrote:<br class=""><br class="">I’m porting a large vxWorks application and I’m trying to download “ld -r”<br class="">files as you can on vxWorks using the run-time loader. At least on ARM I<br class="">can’t get it to work, it uses the first local address it sees for all occurrences.<br class=""><br class="">Example: Label .LC2 is used in two places, once for the “r” in an fopen() and<br class="">later for a format string. In both cases the address used is 0x419f14, the<br class="">address of “r”.<br class=""><br class="">First is the readelf output, then the disassembly, then debugging output from<br class="">the RTL.<br class=""><br class="">FIRST OCCURRENCE OF .LC2 used as “r” in fopen()<br class="">readelf:<br class="">00000020 0000152f R_ARM_THM_MOVW_ABS_NC 00000008 .LC1<br class="">00000024 00001530 R_ARM_THM_MOVT_ABS 00000008 .LC1<br class="">0000002a 0000162f R_ARM_THM_MOVW_ABS_NC 0000002c .LC2<br class="">0000002e 00001630 R_ARM_THM_MOVT_ABS 0000002c .LC2<br class="">00000034 0000450a R_ARM_THM_CALL 00000000 fopen<br class=""><br class="">Disassemble:<br class=""> if ((fd = fopen(string, "r")) == (0)) {<br class=""> 2a: f240 0100 movw r1, #0<br class=""> 2e: f2c0 0100 movt r1, #0<br class=""> 32: 6878 ldr r0, [r7, #4]<br class=""> 34: f7ff fffe bl 0 <fopen><br class=""><br class="">RTL:<br class="">rtl: THM_MOVT_ABS/THM_MOVW_ABS_NC 0x341f2c0 @ 0x4196dc in bad<br class="">rtl: rel: sym:.LC2(22)=00419f14 type:47 off:0000002a<br class="">rtl: THM_MOVT_ABS/THM_MOVW_ABS_NC 0x7114f649 @ 0x4196e2 in bad<br class="">rtl: rel: sym:.LC2(22)=00419f14 type:48 off:0000002e<br class="">rtl: THM_MOVT_ABS/THM_MOVW_ABS_NC 0x141f2c0 @ 0x4196e6 in bad<br class="">rtl: rel: sym:fopen(69)=000d33c1 type:10 off:00000034<br class=""><br class="">SECOND OCCURRENCE of .LC2 used for the printf format string:<br class=""><br class="">readelf:<br class="">000007a8 00002c2f R_ARM_THM_MOVW_ABS_NC 0000013c .LC2<br class="">000007ac 00002c30 R_ARM_THM_MOVT_ABS 0000013c .LC2<br class="">000007b0 0000330a R_ARM_THM_CALL 00000000 printf<br class=""><br class="">Disassemble:<br class="">7a6: 68f9 ldr r1, [r7, #12]<br class="">7a8: f240 0000 movw r0, #0<br class="">7ac: f2c0 0000 movt r0, #0<br class="">7b0: f7ff fffe bl 0 <printf><br class=""><br class="">RTL:<br class="">rtl: rel: sym:.LC2(44)=00419f14 type:47 off:000007a8<br class="">rtl: THM_MOVT_ABS/THM_MOVW_ABS_NC 0x7014f649 @ 0x419e60 in<br class="">/opt/flatland/arch/arm-stubs-vxstubs/bin/sys-bad<br class="">rtl: rel: sym:.LC2(44)=00419f14 type:48 off:000007ac<br class="">rtl: THM_MOVT_ABS/THM_MOVW_ABS_NC 0x41f2c0 @ 0x419e64 in<br class="">/opt/flatland/arch/arm-stubs-vxstubs/bin/sys-bad<br class="">rtl: rel: sym:printf(51)=000daac9 type:10 off:000007b0<br class=""><br class="">Peter<br class="">-----------------<br class="">Peter Dufault<br class="">HD Associates, Inc. Software and System Engineering<br class=""><br class="">This email is delivered through the public internet using protocols subject to<br class="">interception and tampering.<br class=""><br class="">_______________________________________________<br class="">devel mailing list<br class=""><a href="mailto:devel@rtems.org" class="">devel@rtems.org</a> <<a href="mailto:devel@rtems.org" class="">mailto:devel@rtems.org</a>><br class=""><a href="http://lists.rtems.org/mailman/listinfo/devel" class="">http://lists.rtems.org/mailman/listinfo/devel</a><br class=""></blockquote><br class="">Peter<br class="">-----------------<br class="">Peter Dufault<br class="">HD Associates, Inc. Software and System Engineering<br class=""><br class="">This email is delivered through the public internet using protocols subject to<br class="">interception and tampering.<br class=""><br class=""><br class="">_______________________________________________<br class="">devel mailing list<br class=""><a href="mailto:devel@rtems.org" class="">devel@rtems.org</a><br class="">http://lists.rtems.org/mailman/listinfo/devel<br class=""><br class=""></blockquote></div></div></blockquote></div><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; line-height: normal; border-spacing: 0px; -webkit-text-decorations-in-effect: none;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;">Peter<br class="">-----------------<br class="">Peter Dufault<br class="">HD Associates, Inc. Software and System Engineering</span></font></div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="font-size: 12px;"><br class=""></span></font></div>This email is delivered through the public internet using protocols subject to interception and tampering.</span></div></span></div></div></div></div></div></div></div></div></div>
</div>
<br class=""></div></div></body></html>