aboutsummaryrefslogtreecommitdiff
path: root/Semestr 4/ask/lista8
diff options
context:
space:
mode:
authorFranciszek Malinka <franciszek.malinka@gmail.com>2021-05-06 14:28:59 +0200
committerFranciszek Malinka <franciszek.malinka@gmail.com>2021-05-06 14:28:59 +0200
commitf0bd9763ea4be22f0f235c0f3aa6628944a56c7e (patch)
treec12c047b441bdc520740643e549bd90624601fe8 /Semestr 4/ask/lista8
parentf31c5fa59ee3afafc66bfb53c159eff301b537af (diff)
Aktualizacja
Diffstat (limited to 'Semestr 4/ask/lista8')
-rwxr-xr-xSemestr 4/ask/lista8/._lista_8bin0 -> 212 bytes
-rw-r--r--Semestr 4/ask/lista8/ask21_lista_8.tgzbin0 -> 2136 bytes
-rw-r--r--Semestr 4/ask/lista8/bar.c5
-rw-r--r--Semestr 4/ask/lista8/even.c8
-rw-r--r--Semestr 4/ask/lista8/foo.c5
-rw-r--r--Semestr 4/ask/lista8/lazy.c7
-rw-r--r--Semestr 4/ask/lista8/main.lds39
-rw-r--r--Semestr 4/ask/lista8/merge-1.map300
-rw-r--r--Semestr 4/ask/lista8/merge-2.map301
-rw-r--r--Semestr 4/ask/lista8/mismatch-a.c7
-rw-r--r--Semestr 4/ask/lista8/mismatch-b.c8
-rw-r--r--Semestr 4/ask/lista8/odd.c8
-rw-r--r--Semestr 4/ask/lista8/relo3.c15
-rw-r--r--Semestr 4/ask/lista8/start.c8
-rw-r--r--Semestr 4/ask/lista8/str-a.c10
-rw-r--r--Semestr 4/ask/lista8/str-b.c9
-rw-r--r--Semestr 4/ask/lista8/swap.c18
17 files changed, 748 insertions, 0 deletions
diff --git a/Semestr 4/ask/lista8/._lista_8 b/Semestr 4/ask/lista8/._lista_8
new file mode 100755
index 0000000..893436c
--- /dev/null
+++ b/Semestr 4/ask/lista8/._lista_8
Binary files differ
diff --git a/Semestr 4/ask/lista8/ask21_lista_8.tgz b/Semestr 4/ask/lista8/ask21_lista_8.tgz
new file mode 100644
index 0000000..789c9af
--- /dev/null
+++ b/Semestr 4/ask/lista8/ask21_lista_8.tgz
Binary files differ
diff --git a/Semestr 4/ask/lista8/bar.c b/Semestr 4/ask/lista8/bar.c
new file mode 100644
index 0000000..97fbd4f
--- /dev/null
+++ b/Semestr 4/ask/lista8/bar.c
@@ -0,0 +1,5 @@
+// extern long foo;
+
+int bar = 42;
+// long *foo_p = &foo;
+short dead[15];
diff --git a/Semestr 4/ask/lista8/even.c b/Semestr 4/ask/lista8/even.c
new file mode 100644
index 0000000..5bf8606
--- /dev/null
+++ b/Semestr 4/ask/lista8/even.c
@@ -0,0 +1,8 @@
+int is_odd(long n);
+
+int is_even(long n) {
+ if (n == 0)
+ return 1;
+ else
+ return is_odd(n - 1);
+}
diff --git a/Semestr 4/ask/lista8/foo.c b/Semestr 4/ask/lista8/foo.c
new file mode 100644
index 0000000..080d831
--- /dev/null
+++ b/Semestr 4/ask/lista8/foo.c
@@ -0,0 +1,5 @@
+// extern int bar;
+
+long foo = 19;
+// int *bar_p = &bar;
+char code[17];
diff --git a/Semestr 4/ask/lista8/lazy.c b/Semestr 4/ask/lista8/lazy.c
new file mode 100644
index 0000000..fb08cf7
--- /dev/null
+++ b/Semestr 4/ask/lista8/lazy.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+int main(void) {
+ puts("first time");
+ puts("second time");
+ return 0;
+}
diff --git a/Semestr 4/ask/lista8/main.lds b/Semestr 4/ask/lista8/main.lds
new file mode 100644
index 0000000..25a4ca9
--- /dev/null
+++ b/Semestr 4/ask/lista8/main.lds
@@ -0,0 +1,39 @@
+OUTPUT_FORMAT("elf64-x86-64")
+OUTPUT_ARCH(i386:x86-64)
+ENTRY(_start)
+PHDRS
+{
+ code PT_LOAD FLAGS(5);
+ rodata PT_LOAD FLAGS(4);
+ data PT_LOAD FLAGS(6);
+}
+SECTIONS
+{
+ . = 0x400000 + SIZEOF_HEADERS;
+
+ .text :
+ {
+ *(.text .text.*)
+ } : code
+
+ .rodata :
+ {
+ *(.rodata .rodata.*)
+ } : rodata
+
+ .data :
+ {
+ *(.data .data.*)
+ } : data
+
+ .bss :
+ {
+ *(.bss .bss.*)
+ *(COMMON)
+ } : data
+
+ /DISCARD/ :
+ {
+ *(.note.gnu.property)
+ }
+}
diff --git a/Semestr 4/ask/lista8/merge-1.map b/Semestr 4/ask/lista8/merge-1.map
new file mode 100644
index 0000000..2e93e7c
--- /dev/null
+++ b/Semestr 4/ask/lista8/merge-1.map
@@ -0,0 +1,300 @@
+
+Merging program properties
+
+
+Discarded input sections
+
+ .note.gnu.property
+ 0x0000000000000000 0x20 bar.o
+
+Memory Configuration
+
+Name Origin Length Attributes
+*default* 0x0000000000000000 0xffffffffffffffff
+
+Linker script and memory map
+
+LOAD foo.o
+LOAD bar.o
+
+.interp
+ *(.interp)
+
+.note.gnu.property
+ 0x0000000000000000 0x20
+ .note.gnu.property
+ 0x0000000000000000 0x20 foo.o
+
+.note.gnu.build-id
+ *(.note.gnu.build-id)
+
+.hash
+ *(.hash)
+
+.gnu.hash
+ *(.gnu.hash)
+
+.dynsym
+ *(.dynsym)
+
+.dynstr
+ *(.dynstr)
+
+.gnu.version
+ *(.gnu.version)
+
+.gnu.version_d
+ *(.gnu.version_d)
+
+.gnu.version_r
+ *(.gnu.version_r)
+
+.rela.init
+ *(.rela.init)
+
+.rela.text
+ *(.rela.text)
+
+.rela.fini
+ *(.rela.fini)
+
+.rela.rodata
+ *(.rela.rodata)
+
+.rela.data.rel.ro
+ *(.rela.data.rel.ro)
+
+.rela.data
+ *(.rela.data)
+
+.rela.tdata
+ *(.rela.tdata)
+
+.rela.tbss
+ *(.rela.tbss)
+
+.rela.ctors
+ *(.rela.ctors)
+
+.rela.dtors
+ *(.rela.dtors)
+
+.rela.got
+ *(.rela.got)
+
+.rela.bss
+ *(.rela.bss)
+
+.rela.ldata
+ *(.rela.ldata)
+
+.rela.lbss
+ *(.rela.lbss)
+
+.rela.lrodata
+ *(.rela.lrodata)
+
+.rela.ifunc
+ *(.rela.ifunc)
+
+.rela.plt
+ *(.rela.plt)
+
+.init
+ *(SORT_NONE(.init))
+
+.plt
+ *(.plt)
+
+.plt.got
+ *(.plt.got)
+
+.plt.sec
+ *(.plt.sec)
+
+.text 0x0000000000000000 0x0
+ *(.text .stub)
+ .text 0x0000000000000000 0x0 foo.o
+ .text 0x0000000000000000 0x0 bar.o
+ *(.gnu.warning)
+
+.fini
+ *(SORT_NONE(.fini))
+
+.rodata
+ *(.rodata)
+
+.rodata1
+ *(.rodata1)
+
+.eh_frame_hdr
+ *(.eh_frame_hdr)
+
+.eh_frame
+ *(.eh_frame)
+
+.gcc_except_table
+ *(.gcc_except_table)
+
+.gnu_extab
+ *(.gnu_extab*)
+
+.exception_ranges
+ *(.exception_ranges)
+
+.eh_frame
+ *(.eh_frame)
+
+.gnu_extab
+ *(.gnu_extab)
+
+.gcc_except_table
+ *(.gcc_except_table)
+
+.exception_ranges
+ *(.exception_ranges)
+
+.tdata
+ *(.tdata)
+
+.tbss
+ *(.tbss)
+
+.jcr
+ *(.jcr)
+
+.dynamic
+ *(.dynamic)
+
+.got
+ *(.got)
+
+.got.plt
+ *(.got.plt)
+
+.data 0x0000000000000000 0xc
+ *(.data)
+ .data 0x0000000000000000 0x8 foo.o
+ 0x0000000000000000 foo
+ .data 0x0000000000000008 0x4 bar.o
+ 0x0000000000000008 bar
+
+.data1
+ *(.data1)
+
+.bss 0x0000000000000000 0x3e
+ *(.bss)
+ .bss 0x0000000000000000 0x11 foo.o
+ 0x0000000000000000 code
+ *fill* 0x0000000000000011 0xf
+ .bss 0x0000000000000020 0x1e bar.o
+ 0x0000000000000020 dead
+
+.lbss
+ *(.lbss)
+
+.lrodata
+ *(.lrodata)
+
+.ldata
+ *(.ldata)
+
+.stab
+ *(.stab)
+
+.stabstr
+ *(.stabstr)
+
+.stab.excl
+ *(.stab.excl)
+
+.stab.exclstr
+ *(.stab.exclstr)
+
+.stab.index
+ *(.stab.index)
+
+.stab.indexstr
+ *(.stab.indexstr)
+
+.comment 0x0000000000000000 0x56
+ *(.comment)
+ .comment 0x0000000000000000 0x2b foo.o
+ .comment 0x000000000000002b 0x2b bar.o
+
+.note.GNU-stack
+ 0x0000000000000000 0x0
+ .note.GNU-stack
+ 0x0000000000000000 0x0 foo.o
+ .note.GNU-stack
+ 0x0000000000000000 0x0 bar.o
+
+.gnu.build.attributes
+ *(.gnu.build.attributes)
+
+.debug
+ *(.debug)
+
+.line
+ *(.line)
+
+.debug_srcinfo
+ *(.debug_srcinfo)
+
+.debug_sfnames
+ *(.debug_sfnames)
+
+.debug_aranges
+ *(.debug_aranges)
+
+.debug_pubnames
+ *(.debug_pubnames)
+
+.debug_info
+ *(.debug_info)
+
+.debug_abbrev
+ *(.debug_abbrev)
+
+.debug_line
+ *(.debug_line)
+
+.debug_frame
+ *(.debug_frame)
+
+.debug_str
+ *(.debug_str)
+
+.debug_loc
+ *(.debug_loc)
+
+.debug_macinfo
+ *(.debug_macinfo)
+
+.debug_weaknames
+ *(.debug_weaknames)
+
+.debug_funcnames
+ *(.debug_funcnames)
+
+.debug_typenames
+ *(.debug_typenames)
+
+.debug_varnames
+ *(.debug_varnames)
+
+.debug_pubtypes
+ *(.debug_pubtypes)
+
+.debug_ranges
+ *(.debug_ranges)
+
+.debug_macro
+ *(.debug_macro)
+
+.debug_addr
+ *(.debug_addr)
+
+.gnu.attributes
+ *(.gnu.attributes)
+OUTPUT(merge-1.o elf64-x86-64)
diff --git a/Semestr 4/ask/lista8/merge-2.map b/Semestr 4/ask/lista8/merge-2.map
new file mode 100644
index 0000000..2677803
--- /dev/null
+++ b/Semestr 4/ask/lista8/merge-2.map
@@ -0,0 +1,301 @@
+
+Merging program properties
+
+
+Discarded input sections
+
+ .note.gnu.property
+ 0x0000000000000000 0x20 foo.o
+
+Memory Configuration
+
+Name Origin Length Attributes
+*default* 0x0000000000000000 0xffffffffffffffff
+
+Linker script and memory map
+
+LOAD bar.o
+LOAD foo.o
+
+.interp
+ *(.interp)
+
+.note.gnu.property
+ 0x0000000000000000 0x20
+ .note.gnu.property
+ 0x0000000000000000 0x20 bar.o
+
+.note.gnu.build-id
+ *(.note.gnu.build-id)
+
+.hash
+ *(.hash)
+
+.gnu.hash
+ *(.gnu.hash)
+
+.dynsym
+ *(.dynsym)
+
+.dynstr
+ *(.dynstr)
+
+.gnu.version
+ *(.gnu.version)
+
+.gnu.version_d
+ *(.gnu.version_d)
+
+.gnu.version_r
+ *(.gnu.version_r)
+
+.rela.init
+ *(.rela.init)
+
+.rela.text
+ *(.rela.text)
+
+.rela.fini
+ *(.rela.fini)
+
+.rela.rodata
+ *(.rela.rodata)
+
+.rela.data.rel.ro
+ *(.rela.data.rel.ro)
+
+.rela.data
+ *(.rela.data)
+
+.rela.tdata
+ *(.rela.tdata)
+
+.rela.tbss
+ *(.rela.tbss)
+
+.rela.ctors
+ *(.rela.ctors)
+
+.rela.dtors
+ *(.rela.dtors)
+
+.rela.got
+ *(.rela.got)
+
+.rela.bss
+ *(.rela.bss)
+
+.rela.ldata
+ *(.rela.ldata)
+
+.rela.lbss
+ *(.rela.lbss)
+
+.rela.lrodata
+ *(.rela.lrodata)
+
+.rela.ifunc
+ *(.rela.ifunc)
+
+.rela.plt
+ *(.rela.plt)
+
+.init
+ *(SORT_NONE(.init))
+
+.plt
+ *(.plt)
+
+.plt.got
+ *(.plt.got)
+
+.plt.sec
+ *(.plt.sec)
+
+.text 0x0000000000000000 0x0
+ *(.text .stub)
+ .text 0x0000000000000000 0x0 bar.o
+ .text 0x0000000000000000 0x0 foo.o
+ *(.gnu.warning)
+
+.fini
+ *(SORT_NONE(.fini))
+
+.rodata
+ *(.rodata)
+
+.rodata1
+ *(.rodata1)
+
+.eh_frame_hdr
+ *(.eh_frame_hdr)
+
+.eh_frame
+ *(.eh_frame)
+
+.gcc_except_table
+ *(.gcc_except_table)
+
+.gnu_extab
+ *(.gnu_extab*)
+
+.exception_ranges
+ *(.exception_ranges)
+
+.eh_frame
+ *(.eh_frame)
+
+.gnu_extab
+ *(.gnu_extab)
+
+.gcc_except_table
+ *(.gcc_except_table)
+
+.exception_ranges
+ *(.exception_ranges)
+
+.tdata
+ *(.tdata)
+
+.tbss
+ *(.tbss)
+
+.jcr
+ *(.jcr)
+
+.dynamic
+ *(.dynamic)
+
+.got
+ *(.got)
+
+.got.plt
+ *(.got.plt)
+
+.data 0x0000000000000000 0x10
+ *(.data)
+ .data 0x0000000000000000 0x4 bar.o
+ 0x0000000000000000 bar
+ *fill* 0x0000000000000004 0x4
+ .data 0x0000000000000008 0x8 foo.o
+ 0x0000000000000008 foo
+
+.data1
+ *(.data1)
+
+.bss 0x0000000000000000 0x31
+ *(.bss)
+ .bss 0x0000000000000000 0x1e bar.o
+ 0x0000000000000000 dead
+ *fill* 0x000000000000001e 0x2
+ .bss 0x0000000000000020 0x11 foo.o
+ 0x0000000000000020 code
+
+.lbss
+ *(.lbss)
+
+.lrodata
+ *(.lrodata)
+
+.ldata
+ *(.ldata)
+
+.stab
+ *(.stab)
+
+.stabstr
+ *(.stabstr)
+
+.stab.excl
+ *(.stab.excl)
+
+.stab.exclstr
+ *(.stab.exclstr)
+
+.stab.index
+ *(.stab.index)
+
+.stab.indexstr
+ *(.stab.indexstr)
+
+.comment 0x0000000000000000 0x56
+ *(.comment)
+ .comment 0x0000000000000000 0x2b bar.o
+ .comment 0x000000000000002b 0x2b foo.o
+
+.note.GNU-stack
+ 0x0000000000000000 0x0
+ .note.GNU-stack
+ 0x0000000000000000 0x0 bar.o
+ .note.GNU-stack
+ 0x0000000000000000 0x0 foo.o
+
+.gnu.build.attributes
+ *(.gnu.build.attributes)
+
+.debug
+ *(.debug)
+
+.line
+ *(.line)
+
+.debug_srcinfo
+ *(.debug_srcinfo)
+
+.debug_sfnames
+ *(.debug_sfnames)
+
+.debug_aranges
+ *(.debug_aranges)
+
+.debug_pubnames
+ *(.debug_pubnames)
+
+.debug_info
+ *(.debug_info)
+
+.debug_abbrev
+ *(.debug_abbrev)
+
+.debug_line
+ *(.debug_line)
+
+.debug_frame
+ *(.debug_frame)
+
+.debug_str
+ *(.debug_str)
+
+.debug_loc
+ *(.debug_loc)
+
+.debug_macinfo
+ *(.debug_macinfo)
+
+.debug_weaknames
+ *(.debug_weaknames)
+
+.debug_funcnames
+ *(.debug_funcnames)
+
+.debug_typenames
+ *(.debug_typenames)
+
+.debug_varnames
+ *(.debug_varnames)
+
+.debug_pubtypes
+ *(.debug_pubtypes)
+
+.debug_ranges
+ *(.debug_ranges)
+
+.debug_macro
+ *(.debug_macro)
+
+.debug_addr
+ *(.debug_addr)
+
+.gnu.attributes
+ *(.gnu.attributes)
+OUTPUT(merge-2.o elf64-x86-64)
diff --git a/Semestr 4/ask/lista8/mismatch-a.c b/Semestr 4/ask/lista8/mismatch-a.c
new file mode 100644
index 0000000..39436f2
--- /dev/null
+++ b/Semestr 4/ask/lista8/mismatch-a.c
@@ -0,0 +1,7 @@
+/* mismatch-a.c */
+void p2(void);
+
+int main() {
+ p2();
+ return 0;
+}
diff --git a/Semestr 4/ask/lista8/mismatch-b.c b/Semestr 4/ask/lista8/mismatch-b.c
new file mode 100644
index 0000000..451d5b3
--- /dev/null
+++ b/Semestr 4/ask/lista8/mismatch-b.c
@@ -0,0 +1,8 @@
+/* mismatch-b.c */
+#include <stdio.h>
+
+char main;
+
+void p2() {
+ printf("0x%x\n", main);
+}
diff --git a/Semestr 4/ask/lista8/odd.c b/Semestr 4/ask/lista8/odd.c
new file mode 100644
index 0000000..c32961e
--- /dev/null
+++ b/Semestr 4/ask/lista8/odd.c
@@ -0,0 +1,8 @@
+int is_even(long n);
+
+int is_odd(long n) {
+ if (n == 0)
+ return 0;
+ else
+ return is_even(n - 1);
+}
diff --git a/Semestr 4/ask/lista8/relo3.c b/Semestr 4/ask/lista8/relo3.c
new file mode 100644
index 0000000..6aca7b6
--- /dev/null
+++ b/Semestr 4/ask/lista8/relo3.c
@@ -0,0 +1,15 @@
+int relo3(int val) {
+ switch (val) {
+ case 100:
+ return val;
+ case 101:
+ return val + 1;
+ case 103:
+ case 104:
+ return val + 3;
+ case 105:
+ return val + 5;
+ default:
+ return val + 6;
+ }
+}
diff --git a/Semestr 4/ask/lista8/start.c b/Semestr 4/ask/lista8/start.c
new file mode 100644
index 0000000..a875ace
--- /dev/null
+++ b/Semestr 4/ask/lista8/start.c
@@ -0,0 +1,8 @@
+int is_even(long);
+
+void _start(void) {
+ asm volatile(
+ "syscall"
+ : /* no output */
+ : "a" (0x3c), "D" (is_even(42)));
+}
diff --git a/Semestr 4/ask/lista8/str-a.c b/Semestr 4/ask/lista8/str-a.c
new file mode 100644
index 0000000..3b0fb36
--- /dev/null
+++ b/Semestr 4/ask/lista8/str-a.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+char *somestr(void);
+
+int main(void) {
+ char *s = somestr();
+ s[5] = '\0';
+ puts(s);
+ return 0;
+}
diff --git a/Semestr 4/ask/lista8/str-b.c b/Semestr 4/ask/lista8/str-b.c
new file mode 100644
index 0000000..50101cb
--- /dev/null
+++ b/Semestr 4/ask/lista8/str-b.c
@@ -0,0 +1,9 @@
+#include <stdlib.h>
+#include <string.h>
+
+char *somestr(void) {
+ char *buf = malloc(sizeof("Hello, world!"));
+ strcpy(buf, "Hello, world!");
+ return buf;
+}
+
diff --git a/Semestr 4/ask/lista8/swap.c b/Semestr 4/ask/lista8/swap.c
new file mode 100644
index 0000000..e1966fd
--- /dev/null
+++ b/Semestr 4/ask/lista8/swap.c
@@ -0,0 +1,18 @@
+extern int buf[];
+
+int *bufp0 = &buf[0];
+static int *bufp1;
+
+static void incr() {
+ static int count = 0;
+ count++;
+}
+
+void swap() {
+ int temp;
+ incr();
+ bufp1 = &buf[1];
+ temp = *bufp0;
+ *bufp0 = *bufp1;
+ *bufp1 = temp;
+}