diff --git a/modules/objfmts/coff/coff-objfmt.c b/modules/objfmts/coff/coff-objfmt.c index 09e58c6e..0f941569 100644 --- a/modules/objfmts/coff/coff-objfmt.c +++ b/modules/objfmts/coff/coff-objfmt.c @@ -572,8 +572,8 @@ coff_objfmt_output_value(yasm_value *value, unsigned char *buf, intn_minus = bc->offset; } - if (value->seg_of || value->section_rel) { - /* Segment or section-relative generation; zero value. */ + if (value->seg_of) { + /* Segment generation; zero value. */ intn_val = 0; intn_minus = 0; } @@ -1842,6 +1842,39 @@ dir_ident(yasm_object *object, yasm_valparamhead *valparams, yasm_bc_create_data(&dvs, 1, 1, object->arch, line)); } +static void +dir_secrel32(yasm_object *object, yasm_valparamhead *valparams, + yasm_valparamhead *objext_valparams, unsigned long line) +{ + yasm_datavalhead dvs; + yasm_valparam *vp; + + if (!object->cur_section) { + yasm_error_set(YASM_ERROR_SYNTAX, + N_(".secrel32 can only be used inside of a section")); + return; + } + + vp = yasm_vps_first(valparams); + yasm_dvs_initialize(&dvs); + do { + yasm_expr *e = yasm_vp_expr(vp, object->symtab, line); + yasm_dataval *dv; + if (!e) { + yasm_error_set(YASM_ERROR_VALUE, + N_(".secrel32 requires expressions")); + yasm_dvs_delete(&dvs); + return; + } + dv = yasm_dv_create_expr(e); + yasm_dv_get_value(dv)->section_rel = 1; + yasm_dvs_append(&dvs, dv); + } while ((vp = yasm_vps_next(vp))); + + yasm_section_bcs_append(object->cur_section, + yasm_bc_create_data(&dvs, 4, 0, object->arch, line)); +} + static void dir_def(yasm_object *object, yasm_valparamhead *valparams, yasm_valparamhead *objext_valparams, unsigned long line) @@ -2293,6 +2326,7 @@ static const yasm_directive coff_objfmt_directives[] = { { ".endef", "gas", dir_endef, YASM_DIR_ANY }, { ".scl", "gas", dir_scl, YASM_DIR_ARG_REQUIRED }, { ".type", "gas", dir_type, YASM_DIR_ARG_REQUIRED }, + { ".secrel32", "gas", dir_secrel32, YASM_DIR_ARG_REQUIRED }, { NULL, NULL, NULL, 0 } }; @@ -2331,6 +2365,7 @@ static const yasm_directive win32_objfmt_directives[] = { { ".endef", "gas", dir_endef, YASM_DIR_ANY }, { ".scl", "gas", dir_scl, YASM_DIR_ARG_REQUIRED }, { ".type", "gas", dir_type, YASM_DIR_ARG_REQUIRED }, + { ".secrel32", "gas", dir_secrel32, YASM_DIR_ARG_REQUIRED }, { ".export", "gas", dir_export, YASM_DIR_ID_REQUIRED }, { "export", "nasm", dir_export, YASM_DIR_ID_REQUIRED }, { ".safeseh", "gas", dir_safeseh, YASM_DIR_ID_REQUIRED }, @@ -2380,6 +2415,7 @@ static const yasm_directive win64_objfmt_directives[] = { { ".endef", "gas", dir_endef, YASM_DIR_ANY }, { ".scl", "gas", dir_scl, YASM_DIR_ARG_REQUIRED }, { ".type", "gas", dir_type, YASM_DIR_ARG_REQUIRED }, + { ".secrel32", "gas", dir_secrel32, YASM_DIR_ARG_REQUIRED }, { ".export", "gas", dir_export, YASM_DIR_ID_REQUIRED }, { "export", "nasm", dir_export, YASM_DIR_ID_REQUIRED }, { ".proc_frame", "gas", dir_proc_frame, YASM_DIR_ID_REQUIRED }, diff --git a/modules/objfmts/win32/tests/gas/Makefile.inc b/modules/objfmts/win32/tests/gas/Makefile.inc index 8a00372c..b2948acf 100644 --- a/modules/objfmts/win32/tests/gas/Makefile.inc +++ b/modules/objfmts/win32/tests/gas/Makefile.inc @@ -7,3 +7,5 @@ EXTRA_DIST += modules/objfmts/win32/tests/gas/win32at.asm EXTRA_DIST += modules/objfmts/win32/tests/gas/win32at.hex EXTRA_DIST += modules/objfmts/win32/tests/gas/win32def.asm EXTRA_DIST += modules/objfmts/win32/tests/gas/win32def.hex +EXTRA_DIST += modules/objfmts/win32/tests/gas/win32secrel32.asm +EXTRA_DIST += modules/objfmts/win32/tests/gas/win32secrel32.hex diff --git a/modules/objfmts/win32/tests/gas/win32secrel32.asm b/modules/objfmts/win32/tests/gas/win32secrel32.asm new file mode 100644 index 00000000..0e8a82f7 --- /dev/null +++ b/modules/objfmts/win32/tests/gas/win32secrel32.asm @@ -0,0 +1,80 @@ +# [oformat win32] +.text + + .ascii ">>>>" +pre04: .ascii "<<<<" + .ascii ">>>>>" +pre0d: .ascii "<<<" + .ascii ">>>>>>" +pre16: .ascii "<<" + .ascii ">>>>>>>" +pre1f: .ascii "<" + +.data + + .ascii ">>>>" +sam04: .ascii "<<<<" + .ascii ">>>>>" +sam0d: .ascii "<<<" + .ascii ">>>>>>" +sam16: .ascii "<<" + .ascii ">>>>>>>" +sam1f: .ascii "<" + + .ascii ">>>>" + .secrel32 pre04 + .byte 0x11 + .secrel32 pre0d + .byte 0x11 + .secrel32 pre16 + .byte 0x11 + .secrel32 pre1f + .byte 0x11 + .ascii "<<<<<<<<" + + .ascii ">>>>" + .secrel32 sam04 + .byte 0x11 + .secrel32 sam0d + .byte 0x11 + .secrel32 sam16 + .byte 0x11 + .secrel32 sam1f + .byte 0x11 + .ascii "<<<<<<<<" + + .ascii ">>>>" + .secrel32 nex04 + .byte 0x11 + .secrel32 nex0d + .byte 0x11 + .secrel32 nex16 + .byte 0x11 + .secrel32 nex1f + .byte 0x11 + .ascii "<<<<<<<<" + + .ascii ">>>>" + .secrel32 ext24 + .byte 0x11 + .secrel32 ext2d + .byte 0x11 + .secrel32 ext36 + .byte 0x11 + .secrel32 ext3f + .byte 0x11 + .ascii "<<<<<<<<" + +.section .rdata + + .ascii ">>>>" +nex04: .ascii "<<<<" + .ascii ">>>>>" +nex0d: .ascii "<<<" + .ascii ">>>>>>" +nex16: .ascii "<<" + .ascii ">>>>>>>" +nex1f: .ascii "<" + .ascii ">>>>" + + .p2align 4,0 diff --git a/modules/objfmts/win32/tests/gas/win32secrel32.hex b/modules/objfmts/win32/tests/gas/win32secrel32.hex new file mode 100644 index 00000000..28cc8643 --- /dev/null +++ b/modules/objfmts/win32/tests/gas/win32secrel32.hex @@ -0,0 +1,778 @@ +4c +01 +03 +00 +00 +00 +00 +00 +1c +02 +00 +00 +0d +00 +00 +00 +00 +00 +0c +01 +2e +74 +65 +78 +74 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +20 +00 +00 +00 +8c +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +20 +00 +50 +60 +2e +64 +61 +74 +61 +00 +00 +00 +20 +00 +00 +00 +00 +00 +00 +00 +a0 +00 +00 +00 +ac +00 +00 +00 +4c +01 +00 +00 +00 +00 +00 +00 +10 +00 +00 +00 +40 +00 +30 +c0 +2e +72 +64 +61 +74 +61 +00 +00 +c0 +00 +00 +00 +00 +00 +00 +00 +30 +00 +00 +00 +ec +01 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +40 +00 +50 +40 +3e +3e +3e +3e +3c +3c +3c +3c +3e +3e +3e +3e +3e +3c +3c +3c +3e +3e +3e +3e +3e +3e +3c +3c +3e +3e +3e +3e +3e +3e +3e +3c +3e +3e +3e +3e +3c +3c +3c +3c +3e +3e +3e +3e +3e +3c +3c +3c +3e +3e +3e +3e +3e +3e +3c +3c +3e +3e +3e +3e +3e +3e +3e +3c +3e +3e +3e +3e +04 +00 +00 +00 +11 +0d +00 +00 +00 +11 +16 +00 +00 +00 +11 +1f +00 +00 +00 +11 +3c +3c +3c +3c +3c +3c +3c +3c +3e +3e +3e +3e +04 +00 +00 +00 +11 +0d +00 +00 +00 +11 +16 +00 +00 +00 +11 +1f +00 +00 +00 +11 +3c +3c +3c +3c +3c +3c +3c +3c +3e +3e +3e +3e +04 +00 +00 +00 +11 +0d +00 +00 +00 +11 +16 +00 +00 +00 +11 +1f +00 +00 +00 +11 +3c +3c +3c +3c +3c +3c +3c +3c +3e +3e +3e +3e +00 +00 +00 +00 +11 +00 +00 +00 +00 +11 +00 +00 +00 +00 +11 +00 +00 +00 +00 +11 +3c +3c +3c +3c +3c +3c +3c +3c +24 +00 +00 +00 +03 +00 +00 +00 +0b +00 +29 +00 +00 +00 +03 +00 +00 +00 +0b +00 +2e +00 +00 +00 +03 +00 +00 +00 +0b +00 +33 +00 +00 +00 +03 +00 +00 +00 +0b +00 +44 +00 +00 +00 +05 +00 +00 +00 +0b +00 +49 +00 +00 +00 +05 +00 +00 +00 +0b +00 +4e +00 +00 +00 +05 +00 +00 +00 +0b +00 +53 +00 +00 +00 +05 +00 +00 +00 +0b +00 +64 +00 +00 +00 +0b +00 +00 +00 +0b +00 +69 +00 +00 +00 +0b +00 +00 +00 +0b +00 +6e +00 +00 +00 +0b +00 +00 +00 +0b +00 +73 +00 +00 +00 +0b +00 +00 +00 +0b +00 +84 +00 +00 +00 +07 +00 +00 +00 +0b +00 +89 +00 +00 +00 +08 +00 +00 +00 +0b +00 +8e +00 +00 +00 +09 +00 +00 +00 +0b +00 +93 +00 +00 +00 +0a +00 +00 +00 +0b +00 +3e +3e +3e +3e +3c +3c +3c +3c +3e +3e +3e +3e +3e +3c +3c +3c +3e +3e +3e +3e +3e +3e +3c +3c +3e +3e +3e +3e +3e +3e +3e +3c +3e +3e +3e +3e +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +2e +66 +69 +6c +65 +00 +00 +00 +00 +00 +00 +00 +fe +ff +00 +00 +67 +01 +2d +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +40 +66 +65 +61 +74 +2e +30 +30 +01 +00 +00 +00 +ff +ff +00 +00 +03 +00 +2e +74 +65 +78 +74 +00 +00 +00 +00 +00 +00 +00 +01 +00 +00 +00 +03 +01 +20 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +2e +64 +61 +74 +61 +00 +00 +00 +00 +00 +00 +00 +02 +00 +00 +00 +03 +01 +a0 +00 +00 +00 +10 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +65 +78 +74 +32 +34 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +02 +00 +65 +78 +74 +32 +64 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +02 +00 +65 +78 +74 +33 +36 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +02 +00 +65 +78 +74 +33 +66 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +02 +00 +2e +72 +64 +61 +74 +61 +00 +00 +00 +00 +00 +00 +03 +00 +00 +00 +03 +01 +30 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +04 +00 +00 +00