Skip to content

ivan-w/e2t

Repository files navigation

    E2T - A Elf to IBM TEXT utility

Introduction

    The purpose of the utility is to be able to create IBM COFF TEXT files that can be used under VM or OS (VSE ?) from relocatable s390x (31 bit for now) ELF files so as to create executables from compiled languages (gcc only for now) from a linux system (either compiled or cross compiled).

The conversion process

    This version doesn't actually produce a TEXT file, but a IFOX compatible assembly file in CARD format which can then be turned into a TEXT file on the target system.
    The source ELF file is read, checked for compatibility and the various sections are read and transformed into ASM statements.
    PROGBITS sections are treated as Binary Large OBjects (BLOBS) and no attempt is made to interpret the instructions.
    Relocation and Labels are turned into the relevant ASM statements. If the Relocation is located inside a PROGBITS section, it is inserted there.
    GOT and PLT entries are created and resolved since they cannot be processed by linker programs on IBM VM/OS/VSE systems.
    Because IFOX is limited in its label format (8 Characters, Uppercase, No initial number) C labels are mangled using a MD5 hash when it cannot be represented.
    Long displacements to local symbols are resolved locally. Long displacement cannot be resolved externally (see Caveats).
    It is the responsibility of the programmer to transfer the resulting ASM file to the target system for processing.

Caveats
    Depending on the compiler version, target processor and compiler flags, it is possible that the generated ELF file contains Relocations entries which cannot be translated to IFOX assembler. The resulting output will be unususable. One notable example is the relative long displacement to an external symbol. The flags and target should ensure that externals are accessed using the GOT or PLT.
    The utility doesn't understand the s390/s390x ABI used. It is the resposibility, on initial invocation, to set up proper entry and exit procedures to programs (stack, argument passing, return value). This only concerns initial invocation (for example calling "main" from CMS)
    Because C Labels are mangled using hashes, there is a possibility that more than one C label generates the same mangled IFOX label. The program generates 2^38 possible labels. As a result there is a 2% chance of a collision if there are about 100,000 symbols in the program and 50% chance with 600,000 symbols. Collisions are only a concern for local symbols within a single file and for external symbols if link editing multiple files on the target system.
    Because C labels are mangled using hashes, it may make it complicated to debug what C label is related to any IFOX label. However, the C to Mangled label is indicated in the IFOX output as a comment.
    COMMON sections can be translated to COM sections. However, contrary to ELF, the CMS (OS ? VSE ?) linker doesn't consider them as globally visible
    IFOX has a hard limit on the number of ESDs. So large pre-linked programs may not assemble.
    if the relocatable ELF file contains no symbol, the output cannot be used by IFOX
    There is no C Library (but one can create one with the utility).
    PLT processing requires that the Long Displacement facility be enabled

Usage
    e2t [-vXCMN] filename
        -v Show version information
        -X Expose hidden symbols
            When converting libraries to a set of IFOX/TEXT files, some libraries contain hidden symbols but that are useful for linking (for example gcclib). This flags ignores the "hidden" indicator in the ELF files and creates an ENTRY nonetheless
        -C Treat common as DS
            As explained in the caveats section, Common Section can be seen as COM IFOX statements. However, these are not seen as external. Specifying this flag generates a DS and an ENTRY statement instead of a COM statement which may lead to duplicate entries in turn.
        -M Generate an inlined symbol map (experimental)
        -N Do not generate ENTRY statements. This is needed for pre-linked relocatable objects which are large enough to exceed the hard limit of IFOX regarding the number of ESD entries. It is then required to add the necessary ENTRY cards so that linking can be performed. (FOR Example adding an " ENTRY MAIN" line in the output deck)
        -P Generate PLT Calls for local calls. If this flag is not set, calls to local routines do not go through the Procedure Linkage Table (Indirect calls). Calls to external routines still go through the PLT if the flag is not set.

Example
    Consider the following source C file :
****************
extern  char    bar(char);
int foo(char *c,int sz)
{
    int i;
    char s;
    for(i=0,s=0;i<sz;i++)
    {
        s+=bar(c[i]);
    }
    return s;
}
****************
    Compiled with the following :
****************
s390x-linux-gnu-gcc-6 -O3 -fno-asynchronous-unwind-tables -m31 -c e2t_s1.c -o e2t_s1.o
****************
    The following can be done :
****************
/e2t e2t_s1.o
P7K5X00M CSECT * e2t_s1.o
        DC  AL4($$$$SMAP)
W$GCRK7V DS    0D * PROGBITS Section .text
 DC X'909FF024A7FAFFA012A3C0C0'
         DC    AL4(((($$$$$GOT)+2)-*)/2)
 DC X'A7C400191892A7B80000A728000043209000C0E5'
         DC    AL4((((LKM0BC7J)+2)-*)/2)
 DC X'A79A00011AB2A7A6FFF6A72800FF142B5840F098989FF08407F4A7280000A7F4'
 DC X'FFF9070707070707'
$$$$$GOT DS    0D
IP6L2GAL DC    A(BAR)
$$$$$PLT DS    0D
* PLT Entry for bar@PLT
LKM0BC7J DC    X'C010',AL4(((IP6L2GAL+2)-*)/2),X'5811000007F1'
$$$$SMAP DC  C'$$$$SMAP'
         DC  AL4(P7K5X00M)
         DC  AL1(8)
         DC  C'e2t_s1.o'
         DS    0D
         ENTRY FOO * foo
FOO      EQU   W$GCRK7V+0
         EXTRN BAR * bar
$$NM0000 DC   A(-1),A(-1),A(-1)
         DS    0D
         DC    AL4(0)
         END
****************

About

Elf to IBM Text object deck

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published