[root@centos7 aarch64-bare-metal-qemu]# cat libc.s /* Output "Hello world!" to standard output. For Aarch64 (ARM64) architecture with GNU assembler, using Linux libc functions. Assemble with : as -o hello.o hello.aarch64.linux.libc.gas.asm && gcc -o hello hello.o */ .global main .section .text .balign 4 main: stp x29, x30, [sp, -16]! add x29, sp, 0 adrp x0, message add x0, x0, :lo12:message bl printf mov w0, 0 ldp x29, x30, [sp], 16 ret .section .rodata .balign 4 message: .asciz "Hello world!\n\0"
"libc.s" [New] 28L, 473C written [root@centos7 aarch64-bare-metal-qemu]# as -o hello.o libc.s [root@centos7 aarch64-bare-metal-qemu]# gcc -o hello hello.o [root@centos7 aarch64-bare-metal-qemu]# ./hello Hello world! [root@centos7 aarch64-bare-metal-qemu]#
[root@centos7 aarch64-bare-metal-qemu]# ld hello.o -o hello ld: warning: cannot find entry symbol _start; defaulting to 0000000000400078 hello.o: In function `main': (.text+0x10): undefined reference to `printf'
[root@centos7 aarch64-bare-metal-qemu]# gcc -o hello hello.o [root@centos7 aarch64-bare-metal-qemu]# objdump -s -d hello > hello.txt [root@centos7 aarch64-bare-metal-qemu]# cat hello.txt hello: file format elf64-littleaarch64 Contents of section .interp: 400238 2f6c6962 2f6c642d 6c696e75 782d6161 /lib/ld-linux-aa 400248 72636836 342e736f 2e3100 rch64.so.1. Contents of section .note.ABI-tag: 400254 04000000 10000000 01000000 474e5500 ............GNU. 400264 00000000 03000000 07000000 00000000 ................ Contents of section .note.gnu.build-id: 400274 04000000 14000000 03000000 474e5500 ............GNU. 400284 26121295 64b374d0 4920ed05 08b6775a &...d.t.I ....wZ 400294 ecd5f11f .... Contents of section .gnu.hash: 400298 03000000 02000000 01000000 06000000 ................ 4002a8 00000000 00402021 00000000 02000000 .....@ !........ 4002b8 04000000 7ced110f b92b6b15 2f4e3df6 ....|....+k./N=. Contents of section .dynsym: 4002c8 00000000 00000000 00000000 00000000 ................ 4002d8 00000000 00000000 2a000000 20000000 ........*... ... 4002e8 00000000 00000000 00000000 00000000 ................ 4002f8 0b000000 12000000 00000000 00000000 ................ 400308 00000000 00000000 11000000 12000000 ................ 400318 00000000 00000000 00000000 00000000 ................ 400328 18000000 12000000 00000000 00000000 ................ 400338 00000000 00000000 ........ Contents of section .dynstr: 400340 006c6962 632e736f 2e360061 626f7274 .libc.so.6.abort 400350 00707269 6e746600 5f5f6c69 62635f73 .printf.__libc_s 400360 74617274 5f6d6169 6e005f5f 676d6f6e tart_main.__gmon 400370 5f737461 72745f5f 00474c49 42435f32 _start__.GLIBC_2 400380 2e313700 .17. Contents of section .gnu.version: 400384 00000000 02000200 0200 .......... Contents of section .gnu.version_r: 400390 01000100 01000000 10000000 00000000 ................ 4003a0 97919606 00000200 39000000 00000000 ........9....... Contents of section .rela.dyn: 4003b0 e0ff4100 00000000 01040000 01000000 ..A............. 4003c0 00000000 00000000 ........ Contents of section .rela.plt: 4003c8 00004200 00000000 02040000 04000000 ..B............. 4003d8 00000000 00000000 08004200 00000000 ..........B..... 4003e8 02040000 01000000 00000000 00000000 ................ 4003f8 10004200 00000000 02040000 02000000 ..B............. 400408 00000000 00000000 18004200 00000000 ..........B..... 400418 02040000 03000000 00000000 00000000 ................ Contents of section .init: 400428 fd7bbfa9 fd030091 2e000094 fd7bc1a8 .{...........{.. 400438 c0035fd6 .._. Contents of section .plt: 400440 f07bbfa9 f00000f0 11fe47f9 10e23f91 .{........G...?. 400450 20021fd6 1f2003d5 1f2003d5 1f2003d5 .... ... ... .. 400460 10010090 110240f9 10020091 20021fd6 ......@..... ... 400470 10010090 110640f9 10220091 20021fd6 ......@..".. ... 400480 10010090 110a40f9 10420091 20021fd6 ......@..B.. ... 400490 10010090 110e40f9 10620091 20021fd6 ......@..b.. ... Contents of section .text: 4004a0 1d0080d2 1e0080d2 fd030091 e50300aa ................ 4004b0 e10340f9 e2230091 e6030091 a0000058 ..@..#.........X 4004c0 c3000058 e4000058 e6ffff97 edffff97 ...X...X........ 4004d0 00064000 00000000 20064000 00000000 ..@..... .@..... 4004e0 98064000 00000000 e00000f0 00f047f9 ..@...........G. 4004f0 400000b4 dfffff17 c0035fd6 00000000 @........._..... 400500 01010090 00010090 21a00091 fd7bbfa9 ........!....{.. 400510 00a00091 211c0091 fd030091 210000cb ....!.......!... 400520 3f3800f1 68000054 fd7bc1a8 c0035fd6 ?8..h..T.{...._. 400530 81000058 a1ffffb4 20003fd6 fbffff17 ...X.... .?..... 400540 00000000 00000000 00010090 01010090 ................ 400550 00a00091 21a00091 210000cb fd7bbfa9 ....!...!....{.. 400560 21fc4393 fd030091 21fc418b 21fc4193 !.C.....!.A.!.A. 400570 610000b5 fd7bc1a8 c0035fd6 a2000058 a....{...._....X 400580 a2ffffb4 40003fd6 fbffff17 1f2003d5 ....@.?...... .. 400590 00000000 00000000 fd7bbea9 fd030091 .........{...... 4005a0 f30b00f9 13010090 60924039 80000035 ........`.@9...5 4005b0 d4ffff97 20008052 60920039 f30b40f9 .... ..R`..9..@. 4005c0 fd7bc2a8 c0035fd6 fd7bbfa9 fd030091 .{...._..{...... 4005d0 e00000f0 010047f9 00003891 810000b4 ......G...8..... 4005e0 c1000058 410000b4 20003fd6 fd7bc1a8 ...XA... .?..{.. 4005f0 d6ffff17 1f2003d5 00000000 00000000 ..... .......... 400600 fd7bbfa9 fd030091 00000090 00001b91 .{.............. 400610 a0ffff97 00008052 fd7bc1a8 c0035fd6 .......R.{...._. 400620 fd7bbca9 fd030091 f35301a9 f76303a9 .{.......S...c.. 400630 f40000f0 f80000f0 18c33791 94e23791 ..........7...7. 400640 940218cb 94fe4393 f55b02a9 f703002a ......C..[.....* 400650 f60301aa f50302aa 130080d2 73ffff97 ............s... 400660 340100b4 037b73f8 e003172a e10316aa 4....{s....*.... 400670 e20315aa 60003fd6 73060091 7f0214eb ....`.?.s....... 400680 21ffff54 f35341a9 f55b42a9 f76343a9 !..T.SA..[B..cC. 400690 fd7bc4a8 c0035fd6 c0035fd6 .{...._..._. Contents of section .fini: 40069c fd7bbfa9 fd030091 fd7bc1a8 c0035fd6 .{.......{...._. Contents of section .rodata: 4006b0 01000200 00000000 00000000 00000000 ................ 4006c0 48656c6c 6f20776f 726c6421 0a0000 Hello world!... Contents of section .eh_frame_hdr: 4006d0 011b033b 3c000000 06000000 30feffff ...;<.......0... 4006e0 58000000 78feffff 80000000 c8feffff X...x........... 4006f0 a8000000 f8feffff d0000000 50ffffff ............P... 400700 f8000000 c8ffffff 30010000 ........0... Contents of section .eh_frame: 400710 14000000 00000000 017a5200 04781e01 .........zR..x.. 400720 1b0c1f00 00000000 24000000 1c000000 ........$....... 400730 d0fdffff 40000000 00440e10 9d029e01 ....@....D...... 400740 430d1d44 0adedd0c 1f00410b 00000000 C..D......A..... 400750 24000000 44000000 f0fdffff 44000000 $...D.......D... 400760 00460e10 9d029e01 420d1d44 0adedd0c .F......B..D.... 400770 1f00410b 00000000 24000000 6c000000 ..A.....$...l... 400780 18feffff 30000000 00410e20 9d049e03 ....0....A. .... 400790 410d1d41 930248de ddd30c1f 00000000 A..A..H......... 4007a0 24000000 94000000 20feffff 2c000000 $....... ...,... 4007b0 00410e10 9d029e01 410d1d48 dedd0c1f .A......A..H.... 4007c0 00000000 00000000 34000000 bc000000 ........4....... 4007d0 50feffff 78000000 00410e40 9d089e07 P...x....A.@.... 4007e0 410d1d42 93069405 97029801 47950496 A..B........G... 4007f0 0352dedd d8d7d6d5 d4d30c1f 00000000 .R.............. 400800 14000000 f4000000 90feffff 04000000 ................ 400810 00000000 00000000 00000000 ............ Contents of section .init_array: 41fdf0 c8054000 00000000 ..@..... Contents of section .fini_array: 41fdf8 98054000 00000000 ..@..... Contents of section .jcr: 41fe00 00000000 00000000 ........ Contents of section .dynamic: 41fe08 01000000 00000000 01000000 00000000 ................ 41fe18 0c000000 00000000 28044000 00000000 ........(.@..... 41fe28 0d000000 00000000 9c064000 00000000 ..........@..... 41fe38 19000000 00000000 f0fd4100 00000000 ..........A..... 41fe48 1b000000 00000000 08000000 00000000 ................ 41fe58 1a000000 00000000 f8fd4100 00000000 ..........A..... 41fe68 1c000000 00000000 08000000 00000000 ................ 41fe78 f5feff6f 00000000 98024000 00000000 ...o......@..... 41fe88 05000000 00000000 40034000 00000000 ........@.@..... 41fe98 06000000 00000000 c8024000 00000000 ..........@..... 41fea8 0a000000 00000000 44000000 00000000 ........D....... 41feb8 0b000000 00000000 18000000 00000000 ................ 41fec8 15000000 00000000 00000000 00000000 ................ 41fed8 03000000 00000000 e8ff4100 00000000 ..........A..... 41fee8 02000000 00000000 60000000 00000000 ........`....... 41fef8 14000000 00000000 07000000 00000000 ................ 41ff08 17000000 00000000 c8034000 00000000 ..........@..... 41ff18 07000000 00000000 b0034000 00000000 ..........@..... 41ff28 08000000 00000000 18000000 00000000 ................ 41ff38 09000000 00000000 18000000 00000000 ................ 41ff48 feffff6f 00000000 90034000 00000000 ...o......@..... 41ff58 ffffff6f 00000000 01000000 00000000 ...o............ 41ff68 f0ffff6f 00000000 84034000 00000000 ...o......@..... 41ff78 00000000 00000000 00000000 00000000 ................ 41ff88 00000000 00000000 00000000 00000000 ................ 41ff98 00000000 00000000 00000000 00000000 ................ 41ffa8 00000000 00000000 00000000 00000000 ................ 41ffb8 00000000 00000000 00000000 00000000 ................ 41ffc8 00000000 00000000 00000000 00000000 ................ Contents of section .got: 41ffd8 08fe4100 00000000 00000000 00000000 ..A............. Contents of section .got.plt: 41ffe8 00000000 00000000 00000000 00000000 ................ 41fff8 00000000 00000000 40044000 00000000 ........@.@..... 420008 40044000 00000000 40044000 00000000 @.@.....@.@..... 420018 40044000 00000000 @.@..... Contents of section .data: 420020 00000000 .... Contents of section .comment: 0000 4743433a 2028474e 55292034 2e382e35 GCC: (GNU) 4.8.5 0010 20323031 35303632 33202852 65642048 20150623 (Red H 0020 61742034 2e382e35 2d343429 00 at 4.8.5-44). Disassembly of section .init: 0000000000400428 <_init>: 400428: a9bf7bfd stp x29, x30, [sp,#-16]! 40042c: 910003fd mov x29, sp 400430: 9400002e bl 4004e8 <call_weak_fn> 400434: a8c17bfd ldp x29, x30, [sp],#16 400438: d65f03c0 ret Disassembly of section .plt: 0000000000400440 <.plt>: 400440: a9bf7bf0 stp x16, x30, [sp,#-16]! 400444: f00000f0 adrp x16, 41f000 <__FRAME_END__+0x1e7e8> 400448: f947fe11 ldr x17, [x16,#4088] 40044c: 913fe210 add x16, x16, #0xff8 400450: d61f0220 br x17 400454: d503201f nop 400458: d503201f nop 40045c: d503201f nop 0000000000400460 <__libc_start_main@plt>: 400460: 90000110 adrp x16, 420000 <__libc_start_main@GLIBC_2.17> 400464: f9400211 ldr x17, [x16] 400468: 91000210 add x16, x16, #0x0 40046c: d61f0220 br x17 0000000000400470 <__gmon_start__@plt>: 400470: 90000110 adrp x16, 420000 <__libc_start_main@GLIBC_2.17> 400474: f9400611 ldr x17, [x16,#8] 400478: 91002210 add x16, x16, #0x8 40047c: d61f0220 br x17 0000000000400480 <abort@plt>: 400480: 90000110 adrp x16, 420000 <__libc_start_main@GLIBC_2.17> 400484: f9400a11 ldr x17, [x16,#16] 400488: 91004210 add x16, x16, #0x10 40048c: d61f0220 br x17 0000000000400490 <printf@plt>: 400490: 90000110 adrp x16, 420000 <__libc_start_main@GLIBC_2.17> 400494: f9400e11 ldr x17, [x16,#24] 400498: 91006210 add x16, x16, #0x18 40049c: d61f0220 br x17 Disassembly of section .text: 00000000004004a0 <_start>: 4004a0: d280001d mov x29, #0x0 // #0 4004a4: d280001e mov x30, #0x0 // #0 4004a8: 910003fd mov x29, sp 4004ac: aa0003e5 mov x5, x0 4004b0: f94003e1 ldr x1, [sp] 4004b4: 910023e2 add x2, sp, #0x8 4004b8: 910003e6 mov x6, sp 4004bc: 580000a0 ldr x0, 4004d0 <_start+0x30> 4004c0: 580000c3 ldr x3, 4004d8 <_start+0x38> 4004c4: 580000e4 ldr x4, 4004e0 <_start+0x40> 4004c8: 97ffffe6 bl 400460 <__libc_start_main@plt> 4004cc: 97ffffed bl 400480 <abort@plt> 4004d0: 00400600 .word 0x00400600 4004d4: 00000000 .word 0x00000000 4004d8: 00400620 .word 0x00400620 4004dc: 00000000 .word 0x00000000 4004e0: 00400698 .word 0x00400698 4004e4: 00000000 .word 0x00000000 00000000004004e8 <call_weak_fn>: 4004e8: f00000e0 adrp x0, 41f000 <__FRAME_END__+0x1e7e8> 4004ec: f947f000 ldr x0, [x0,#4064] 4004f0: b4000040 cbz x0, 4004f8 <call_weak_fn+0x10> 4004f4: 17ffffdf b 400470 <__gmon_start__@plt> 4004f8: d65f03c0 ret 4004fc: 00000000 .inst 0x00000000 ; undefined 0000000000400500 <deregister_tm_clones>: 400500: 90000101 adrp x1, 420000 <__libc_start_main@GLIBC_2.17> 400504: 90000100 adrp x0, 420000 <__libc_start_main@GLIBC_2.17> 400508: 9100a021 add x1, x1, #0x28 40050c: a9bf7bfd stp x29, x30, [sp,#-16]! 400510: 9100a000 add x0, x0, #0x28 400514: 91001c21 add x1, x1, #0x7 400518: 910003fd mov x29, sp 40051c: cb000021 sub x1, x1, x0 400520: f100383f cmp x1, #0xe 400524: 54000068 b.hi 400530 <deregister_tm_clones+0x30> 400528: a8c17bfd ldp x29, x30, [sp],#16 40052c: d65f03c0 ret 400530: 58000081 ldr x1, 400540 <deregister_tm_clones+0x40> 400534: b4ffffa1 cbz x1, 400528 <deregister_tm_clones+0x28> 400538: d63f0020 blr x1 40053c: 17fffffb b 400528 <deregister_tm_clones+0x28> ... 0000000000400548 <register_tm_clones>: 400548: 90000100 adrp x0, 420000 <__libc_start_main@GLIBC_2.17> 40054c: 90000101 adrp x1, 420000 <__libc_start_main@GLIBC_2.17> 400550: 9100a000 add x0, x0, #0x28 400554: 9100a021 add x1, x1, #0x28 400558: cb000021 sub x1, x1, x0 40055c: a9bf7bfd stp x29, x30, [sp,#-16]! 400560: 9343fc21 asr x1, x1, #3 400564: 910003fd mov x29, sp 400568: 8b41fc21 add x1, x1, x1, lsr #63 40056c: 9341fc21 asr x1, x1, #1 400570: b5000061 cbnz x1, 40057c <register_tm_clones+0x34> 400574: a8c17bfd ldp x29, x30, [sp],#16 400578: d65f03c0 ret 40057c: 580000a2 ldr x2, 400590 <register_tm_clones+0x48> 400580: b4ffffa2 cbz x2, 400574 <register_tm_clones+0x2c> 400584: d63f0040 blr x2 400588: 17fffffb b 400574 <register_tm_clones+0x2c> 40058c: d503201f nop ... 0000000000400598 <__do_global_dtors_aux>: 400598: a9be7bfd stp x29, x30, [sp,#-32]! 40059c: 910003fd mov x29, sp 4005a0: f9000bf3 str x19, [sp,#16] 4005a4: 90000113 adrp x19, 420000 <__libc_start_main@GLIBC_2.17> 4005a8: 39409260 ldrb w0, [x19,#36] 4005ac: 35000080 cbnz w0, 4005bc <__do_global_dtors_aux+0x24> 4005b0: 97ffffd4 bl 400500 <deregister_tm_clones> 4005b4: 52800020 mov w0, #0x1 // #1 4005b8: 39009260 strb w0, [x19,#36] 4005bc: f9400bf3 ldr x19, [sp,#16] 4005c0: a8c27bfd ldp x29, x30, [sp],#32 4005c4: d65f03c0 ret 00000000004005c8 <frame_dummy>: 4005c8: a9bf7bfd stp x29, x30, [sp,#-16]! 4005cc: 910003fd mov x29, sp 4005d0: f00000e0 adrp x0, 41f000 <__FRAME_END__+0x1e7e8> 4005d4: f9470001 ldr x1, [x0,#3584] 4005d8: 91380000 add x0, x0, #0xe00 4005dc: b4000081 cbz x1, 4005ec <frame_dummy+0x24> 4005e0: 580000c1 ldr x1, 4005f8 <frame_dummy+0x30> 4005e4: b4000041 cbz x1, 4005ec <frame_dummy+0x24> 4005e8: d63f0020 blr x1 4005ec: a8c17bfd ldp x29, x30, [sp],#16 4005f0: 17ffffd6 b 400548 <register_tm_clones> 4005f4: d503201f nop ... 0000000000400600 <main>: 400600: a9bf7bfd stp x29, x30, [sp,#-16]! 400604: 910003fd mov x29, sp 400608: 90000000 adrp x0, 400000 <_init-0x428> 40060c: 911b0000 add x0, x0, #0x6c0 400610: 97ffffa0 bl 400490 <printf@plt> 400614: 52800000 mov w0, #0x0 // #0 400618: a8c17bfd ldp x29, x30, [sp],#16 40061c: d65f03c0 ret 0000000000400620 <__libc_csu_init>: 400620: a9bc7bfd stp x29, x30, [sp,#-64]! 400624: 910003fd mov x29, sp 400628: a90153f3 stp x19, x20, [sp,#16] 40062c: a90363f7 stp x23, x24, [sp,#48] 400630: f00000f4 adrp x20, 41f000 <__FRAME_END__+0x1e7e8> 400634: f00000f8 adrp x24, 41f000 <__FRAME_END__+0x1e7e8> 400638: 9137c318 add x24, x24, #0xdf0 40063c: 9137e294 add x20, x20, #0xdf8 400640: cb180294 sub x20, x20, x24 400644: 9343fe94 asr x20, x20, #3 400648: a9025bf5 stp x21, x22, [sp,#32] 40064c: 2a0003f7 mov w23, w0 400650: aa0103f6 mov x22, x1 400654: aa0203f5 mov x21, x2 400658: d2800013 mov x19, #0x0 // #0 40065c: 97ffff73 bl 400428 <_init> 400660: b4000134 cbz x20, 400684 <__libc_csu_init+0x64> 400664: f8737b03 ldr x3, [x24,x19,lsl #3] 400668: 2a1703e0 mov w0, w23 40066c: aa1603e1 mov x1, x22 400670: aa1503e2 mov x2, x21 400674: d63f0060 blr x3 400678: 91000673 add x19, x19, #0x1 40067c: eb14027f cmp x19, x20 400680: 54ffff21 b.ne 400664 <__libc_csu_init+0x44> 400684: a94153f3 ldp x19, x20, [sp,#16] 400688: a9425bf5 ldp x21, x22, [sp,#32] 40068c: a94363f7 ldp x23, x24, [sp,#48] 400690: a8c47bfd ldp x29, x30, [sp],#64 400694: d65f03c0 ret 0000000000400698 <__libc_csu_fini>: 400698: d65f03c0 ret Disassembly of section .fini: 000000000040069c <_fini>: 40069c: a9bf7bfd stp x29, x30, [sp,#-16]! 4006a0: 910003fd mov x29, sp 4006a4: a8c17bfd ldp x29, x30, [sp],#16 4006a8: d65f03c0 ret
asm-example