summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2019-07-27 21:26:52 -0700
committerH. Peter Anvin <hpa@zytor.com>2019-07-27 21:26:52 -0700
commit2a308027cd680494288ea9b4614839be4c4ea95b (patch)
tree5eff094f217aca73b1741a4a765a81c6c6afa7d8
parentca1a40fe03a578c6c403240afefde71cc003b13f (diff)
downloadsamples-2a308027cd680494288ea9b4614839be4c4ea95b.tar.gz
samples-2a308027cd680494288ea9b4614839be4c4ea95b.tar.xz
samples-2a308027cd680494288ea9b4614839be4c4ea95b.zip
Use dynamic tags from the OS-specific space for additional info
-rw-r--r--com.ld8
-rw-r--r--exe.ld56
-rw-r--r--testme.s18
3 files changed, 60 insertions, 22 deletions
diff --git a/com.ld b/com.ld
index 069ab41..0f18493 100644
--- a/com.ld
+++ b/com.ld
@@ -101,5 +101,11 @@ SECTIONS
.debug_macro 0 : { *(.debug_macro) }
.debug_addr 0 : { *(.debug_addr) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
- /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
+ /DISCARD/ : {
+ *(.note.GNU-stack)
+ *(.gnu_debuglink)
+ *(.gnu.lto_*)
+ *(.hash)
+ *(.interp)
+ }
}
diff --git a/exe.ld b/exe.ld
index f0f950f..f0d1a70 100644
--- a/exe.ld
+++ b/exe.ld
@@ -95,26 +95,55 @@ SECTIONS
* objects if the dynamic section is not part of a loadable
* segment, so we remove it in postprocessing.
*/
- .exeinfo : {
- LONG(0x05806870); /* Magic number */
- LONG(___.filesize); /* True file size */
- LONG(___.end); /* True emory size */
- /* SEG:OFF forms of ___start and ___stack_top */
- SHORT(___start - "___start!");
- SHORT("___start!");
- SHORT(___stack_end - "___stack_end!");
- SHORT("___stack_end!");
- }
/* PIE linking: give us all the dynamic data including relocations */
- .dynamic : { KEEP(*(.dynamic)) }
+ .dynamic : {
+ /* Special DT tags used by elf2exe */
+
+ /* Final file size */
+ LONG(0x6bb31700);
+ LONG(___.filesize);
+
+ /* Final memory size */
+ LONG(0x6bb31701);
+ LONG(___.end); /* Final memory size */
+
+ /* Seg:off form of entry point */
+ LONG(0x6bb31702);
+ SHORT(___start - "___start!");
+ SHORT("___start!" >> 4);
+
+ /* Seg:off form of the initial stack pointer */
+ LONG(0x6bb31703);
+ SHORT(___stack_end - "___stack_end!");
+ SHORT("___stack_end!" >> 4);
+
+ /*
+ * Base of the stack (usable as temp storage
+ * as it does not need to be zeroed.)
+ */
+ LONG(0x6bb31704);
+ LONG(___stack_start);
+
+ /* Size of the stack */
+ LONG(0x6bb31705);
+ LONG(___stack_size);
+
+ KEEP(*(.dynamic))
+
+ /*
+ * Make sure the dynamic structure is terminated. This
+ * may be redundant with linker-generated data, but won't
+ * hurt; the worst case is 8 bytes wasted.
+ */
+ LONG(0);
+ LONG(0);
+ }
.dynsym : { KEEP(*(.dynsym)) }
.dynstr : { KEEP(*(.dynstr)) }
.gnu.hash : { KEEP(*(.gnu.hash)) }
.rel.dyn : { KEEP(*(.rel*)) }
- HIDDEN(___.header_end = .);
-
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
@@ -161,5 +190,6 @@ SECTIONS
*(.gnu_debuglink)
*(.gnu.lto_*)
*(.hash)
+ *(.interp)
}
}
diff --git a/testme.s b/testme.s
index 3fcec83..6f41edd 100644
--- a/testme.s
+++ b/testme.s
@@ -12,10 +12,10 @@
.SEG._TEXT: /* Local symbol! */
.section "_TEXT$","ax"
-.L_SEG = .SEG._TEXT
+.L.SEG = .SEG._TEXT
.globl ___start, "___start!"
- .equ "___start!", .L.SEG
+.set "___start!", .L.SEG
___start:
mov $0,%ax
.reloc .-2, R_386_SEG16, .SEG.DGROUP
@@ -47,7 +47,7 @@ ___start:
* Return the value of _foo in ax, and its linear address in edx
*/
.globl _get_foo, "_get_foo!"
- .equ "_get_foo!", .L.SEG
+.set "_get_foo!", .L.SEG
_get_foo:
mov _foo,%ax /* foo is in our own data segment */
.reloc .-2, R_386_SUB16, .L.SEG
@@ -59,7 +59,7 @@ _get_foo:
* es:bx
*/
.globl _get_cmdline, "_get_cmdline!"
- .equ "_get_cmdline!", .L.SEG
+.set "_get_cmdline!", .L.SEG
_get_cmdline:
mov $0,%ax
.reloc .-2, R_386_SEG16, "__psp!"
@@ -69,15 +69,17 @@ _get_cmdline:
ret
.section "_DATA$","aw"
+ .balign 2
.L.SEG = .SEG._DATA
- .equ "_other!", .L.SEG
+
+.set "_other!", .L.SEG
_other: .word 0x5678
- .equ "_foo!", .L.SEG
+.set "_foo!", .L.SEG
_foo: .word 0x1234
.section "_BSS$","aw",@nobits
-.L.SEG = .SEG._BSS
.balign 2
+.L.SEG = .SEG._BSS
.globl _nasa, "_nasa!"
- .equ "_nasa!", .L.SEG
+.set "_nasa!", .L.SEG
_nasa: .space 512