LINUX: Run the command: readelf -lW hello Include the output you get in your ans
ID: 3598051 • Letter: L
Question
LINUX: Run the command: readelf -lW hello
Include the output you get in your answer document. What is always true with regards to the virtual addresses of the segments and the offsets in the file?
This is the output of the command readelf -lw hello:
This is hello.c:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
char bye[] = "Goodbye world.";
int unused;
void numbers() {
int i;
for (i = 0; i < 10; ++i) {
printf("%d ", i);
}
}
int main(void) {
pid_t pid;
char mem[64];
puts("Hello rshe001!");
numbers();
pid = getpid();
sprintf(mem, "cat /proc/%d/maps", pid);
system(mem);
puts(bye);
return 0;
}
readelf -lW hello Elf file type is EXEC (Executable file) Entry point 0x4005b0 There are 9 program headers, starting at offset 64 Program Headers: Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align Type PHDR INTERP [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2 LOAD LOAD DYNAMIC NOTE GNU STACK GNU RELRO Section to Segment mapping: Segment Sections. .. .interp .interp .note·ABI-tag .note . gnu . build-id .gnu . hash .dynsym ·dyn str .init array.fini array.icr .dynamic .got .got.plt.data .bss .dynamic .note.ABI-tag .note.gnu.build-id 02 .gnu . ve rsion .gnu . version-r .rela . dyn .rela.plt .init .plt .plt . got .text .fini . rodata .eh-frame-hdr .eh-frame 03 05 eh frame hdr 07 08 .init_array.fini_array .jcr .dynamic .gotExplanation / Answer
Here is output of command : readelf -lw hello
virtual address mod page alignment is always same with file offset mod page alignment.
Elf file type is EXEC (Executable file)
Entry point 0x4005b0
There are 9 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000400040 0x0000000000400040
0x00000000000001f8 0x00000000000001f8 R E 8
INTERP 0x0000000000000238 0x0000000000400238 0x0000000000400238
0x000000000000001c 0x000000000000001c R 1
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000
0x000000000000095c 0x000000000000095c R E 200000
LOAD 0x0000000000000e10 0x0000000000600e10 0x0000000000600e10
0x000000000000025f 0x0000000000000268 RW 200000
DYNAMIC 0x0000000000000e28 0x0000000000600e28 0x0000000000600e28
0x00000000000001d0 0x00000000000001d0 RW 8
NOTE 0x0000000000000254 0x0000000000400254 0x0000000000400254
0x0000000000000044 0x0000000000000044 R 4
GNU_EH_FRAME 0x000000000000080c 0x000000000040080c 0x000000000040080c
0x000000000000003c 0x000000000000003c R 4
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RW 10
GNU_RELRO 0x0000000000000e10 0x0000000000600e10 0x0000000000600e10
0x00000000000001f0 0x00000000000001f0 R 1
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .plt.got .text .fini .rodata .eh_frame_hdr .eh_frame
03 .init_array .fini_array .jcr .dynamic .got .got.plt .data .bss
04 .dynamic
05 .note.ABI-tag .note.gnu.build-id
06 .eh_frame_hdr
07
08 .init_array .fini_array .jcr .dynamic .got
Contents of the .eh_frame section:
00000000 0000000000000014 00000000 CIE
Version: 1
Augmentation: "zR"
Code alignment factor: 1
Data alignment factor: -8
Return address column: 16
Augmentation data: 1b
DW_CFA_def_cfa: r7 (rsp) ofs 8
DW_CFA_offset: r16 (rip) at cfa-8
DW_CFA_undefined: r16 (rip)
00000018 0000000000000014 0000001c FDE cie=00000000 pc=00000000004005b0..00000000004005da
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
00000030 0000000000000014 00000000 CIE
Version: 1
Augmentation: "zR"
Code alignment factor: 1
Data alignment factor: -8
Return address column: 16
Augmentation data: 1b
DW_CFA_def_cfa: r7 (rsp) ofs 8
DW_CFA_offset: r16 (rip) at cfa-8
DW_CFA_nop
DW_CFA_nop
00000048 0000000000000024 0000001c FDE cie=00000030 pc=0000000000400520..00000000004005a0
DW_CFA_def_cfa_offset: 16
DW_CFA_advance_loc: 6 to 0000000000400526
DW_CFA_def_cfa_offset: 24
DW_CFA_advance_loc: 10 to 0000000000400530
DW_CFA_def_cfa_expression (DW_OP_breg7 (rsp): 8; DW_OP_breg16 (rip): 0; DW_OP_lit15; DW_OP_and; DW_OP_lit11; DW_OP_ge; DW_OP_lit3; DW_OP_shl; DW_OP_plus)
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
00000070 000000000000001c 00000044 FDE cie=00000030 pc=00000000004006a6..00000000004006d8
DW_CFA_advance_loc: 1 to 00000000004006a7
DW_CFA_def_cfa_offset: 16
DW_CFA_offset: r6 (rbp) at cfa-16
DW_CFA_advance_loc: 3 to 00000000004006aa
DW_CFA_def_cfa_register: r6 (rbp)
DW_CFA_advance_loc: 45 to 00000000004006d7
DW_CFA_def_cfa: r7 (rsp) ofs 8
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
00000090 000000000000001c 00000064 FDE cie=00000030 pc=00000000004006d8..0000000000400755
DW_CFA_advance_loc: 1 to 00000000004006d9
DW_CFA_def_cfa_offset: 16
DW_CFA_offset: r6 (rbp) at cfa-16
DW_CFA_advance_loc: 3 to 00000000004006dc
DW_CFA_def_cfa_register: r6 (rbp)
DW_CFA_advance_loc1: 120 to 0000000000400754
DW_CFA_def_cfa: r7 (rsp) ofs 8
DW_CFA_nop
DW_CFA_nop
000000b0 0000000000000044 00000084 FDE cie=00000030 pc=0000000000400760..00000000004007c5
DW_CFA_advance_loc: 2 to 0000000000400762
DW_CFA_def_cfa_offset: 16
DW_CFA_offset: r15 (r15) at cfa-16
DW_CFA_advance_loc: 2 to 0000000000400764
DW_CFA_def_cfa_offset: 24
DW_CFA_offset: r14 (r14) at cfa-24
DW_CFA_advance_loc: 5 to 0000000000400769
DW_CFA_def_cfa_offset: 32
DW_CFA_offset: r13 (r13) at cfa-32
DW_CFA_advance_loc: 2 to 000000000040076b
DW_CFA_def_cfa_offset: 40
DW_CFA_offset: r12 (r12) at cfa-40
DW_CFA_advance_loc: 8 to 0000000000400773
DW_CFA_def_cfa_offset: 48
DW_CFA_offset: r6 (rbp) at cfa-48
DW_CFA_advance_loc: 8 to 000000000040077b
DW_CFA_def_cfa_offset: 56
DW_CFA_offset: r3 (rbx) at cfa-56
DW_CFA_advance_loc: 13 to 0000000000400788
DW_CFA_def_cfa_offset: 64
DW_CFA_advance_loc: 50 to 00000000004007ba
DW_CFA_def_cfa_offset: 56
DW_CFA_advance_loc: 1 to 00000000004007bb
DW_CFA_def_cfa_offset: 48
DW_CFA_advance_loc: 1 to 00000000004007bc
DW_CFA_def_cfa_offset: 40
DW_CFA_advance_loc: 2 to 00000000004007be
DW_CFA_def_cfa_offset: 32
DW_CFA_advance_loc: 2 to 00000000004007c0
DW_CFA_def_cfa_offset: 24
DW_CFA_advance_loc: 2 to 00000000004007c2
DW_CFA_def_cfa_offset: 16
DW_CFA_advance_loc: 2 to 00000000004007c4
DW_CFA_def_cfa_offset: 8
DW_CFA_nop
000000f8 0000000000000014 000000cc FDE cie=00000030 pc=00000000004007d0..00000000004007d2
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
DW_CFA_nop
00000110 ZERO terminator
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.