Skip to content

Commit

Permalink
Added
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfram77 committed Nov 1, 2016
1 parent 1129318 commit 702ab3f
Show file tree
Hide file tree
Showing 10 changed files with 468 additions and 0 deletions.
Binary file added ALINK.EXE
Binary file not shown.
156 changes: 156 additions & 0 deletions README.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
ALINK v1.6 is copyright 1998/9 Anthony A.J. Williams. All Rights Reserved.

ALINK is a linker for OBJ and LIB files, and generates MSDOS COM and
MSDOS EXE files, and Win32 PE files. Win32 resource files are also supported
for linking to PE files. MS/Intel OMF and MS-COFF object and library files
are supported. MS-COFF import libraries are not supported, and will cause
an undefined symbol error in a .idata section.

ALINK is free, and as such there is no warranty whatsoever. If anything bad
happens, it is entirely your responsibility.

The command line is:

ALINK [options] filename [options] [filenames] [options] ...

By default ALINK performs a case-sensitive link to an EXE file, without
padding segments. If filenames don't include an extension, .obj is assumed.
Additional parameters can be taken from response files, by specifying a
filename preceded by an @ sign, e.g.

ALINK @response.fil

Blanks lines are ignored, options may be specified together, or on separate
lines. Quoted strings are treated as a single parameter.
Semicolons are treated as the start of a comment, and the rest of the
line will be ignored. If you really want a semicolon, enclose it in
quotes.
Options and filenames can be used in the parameter file, but filenames may
not include wildcards. Multiple response files can be referenced, and
additional response files may be included from within a response file.
Cyclic references are not detected, and will cause the program
to loop until it runs out of memory (never, if the response files don't
contain any options!).

Possible options are:

-c Enable Case sensitive link
-c+ "
-c- Disable Case sensitive link
-p Pad segments (initialise all segments)
-p+ "
-p- Disable segment padding
-o yyy yyy is output filename
-oxxx xxx specifies output format
COM = output COM file
EXE = output EXE file
PE = output Win32 PE file (.EXE)
-m Generate map file
-m+ "
-m- Don't generate map file
-L ddd Add directory ddd to library search list
-h Display this help list
-H "
-? "
-entry name Use public symbol name as the entry point

In addition, for PE files the following options apply:

-base addr Set Image Base (default=4Mb)
-objectalign xxx Set section alignment in memory (default=64K)
-filealign xxx Set section alignment in file (default=512)
-subsys xxx Set windows subsystem to use (default=windows)
windows, win or gui => windows subsystem
console, con or char => console subsystem
native => native subsystem
posix => POSIX subsystem
-subsysver x.y Set subsystem version x.y (default=4.0)
-osver x.y Set OS version x.y (default=1.0)
-heapsize xxx Set heap size (default=1Mb)
-heapcommitsize xxx Set heap commit size (default=4K)
-stacksize xxx Set stack size (default=1Mb)
-stackcommitsize xxx Set stack commit size (default=4K)
-dll Build a DLL instead of an EXE file.
-stub filename Use the specified file as the MSDOS stub.

Note that Windows 3.1=> ver 3.10, 3.5=>ver 3.50
If you type -subsysver 3.1, this is the same as 3.01

The alignments must be powers of 2. ObjectAlign can be 512 to 256Mb, FileAlign can
be 512 to 64K. The Image base and alignments can be specified as decimal numbers, or as
hex numbers prefixed by 0x (in fact, any number format supported by the C function
strtoul). The image base must be a multiple of 64K.

options are case sensitive, so -ocom is invalid, as is -C.

If an output filename is not specified, then the output file is determined
from the output type, and the root of the first object file.

e.g.

ALINK file1.obj -oCOM -o outfile.com

Generates outfile.com from file1.obj

ALINK file2.obj file3.obj -oEXE

Generates file2.exe

Segments from different object files are combined if they have the same name
and class, and are not declared private. Absolute segments are never
combined, and stack segments are always combined.

Segments are emitted in the order they are present in the object files,
unless groups are used. All segments in groups are emitted before segments
not in groups. A segment may not be in more than one group. Segments in groups
are emitted in the order specified in the group definition. If two different
definitions of the same group specify different orders, the first definition
is used.

Thus, if in the second example above, file2.obj contains a group definition
equivalent to

agroup group code,data,stack

and file3.obj contains a group definition equivalent to

agroup group data,stack,bss,code

The final output for agroup will be

code,data,stack,bss

The text output from the linker is quite verbose, and lists all the files as
they are loaded in. Any unrecognised object records will cause an error. Any
recognised, but ignored records, such as LINNUM records and COMENT records
will be printed on the screen. Since debug information is often contained in
COMENT records, this could lead to a lot of output.

The map file will list the segments, publics, imports and exports.

A sample Import library for Win32 is included as win32.lib. All named exports in
Kernel32, User32, GDI32, Shell32, ADVAPI32, version,winmm, lz32,commdlg and commctl
are included. Use

alink -oPE file[.obj] win32.lib to include it.

or specify

INCLUDELIB "win32"

in your source file (TASM)

This consists of a series of entries for import redirection - call
MessageBoxA, and it jumps to [__imp_MessageBoxA], which is in the Import
Table.

Thus calls to imports will run faster if call [__imp_importName] is used
instead of call importName.

See test.asm, my sample program, which calls up a message box both ways.

See rtn.asm for an example program using NASM, and resources.

Any questions, comments or bug reports please email me at

[email protected]
34 changes: 34 additions & 0 deletions TEST.ASM
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ideal

p386

model use32 flat

includelib "win32.lib"
extrn MessageBoxA:near
extrn __imp_MessageBoxA:dword

codeseg

start:
push 0 ; OK button
push offset title1
push offset string1
push 0
call MessageBoxA

push 0 ; OK button
push offset title1
push offset string2
push 0
call large [large __imp_MessageBoxA]

ret

dataseg

string1: db 'hello world, through redirection',13,10,0
title1: db 'Hello',0
string2: db 'hello world, called through import table',13,10,0

end start
78 changes: 78 additions & 0 deletions history.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
New features in v1.6:

* No symbol or segment/section limit
* Fixed bug in PE output IMPORT section with imports from multiple DLLs
* Faster symbol lookup
* Default file extension added to output name
* Support for response files, with comments
* Better support for COFF libraries
* Fixed bug when searching LIB paths, which ignored last path on list
* Added paging to info screen, and updated text of it
* Better case-sensitivity / case-insensitivity handling with libraries
* Added support for symbol alias OMF records

New features in v1.5b:

* Fixed bug in COM/EXE output formats whereby offsets into segments that were less than paragraph aligned (byte, word aligned etc.) were incorrect if segment did not end up paragraph aligned.

New features in v1.5a:

* Fixed bug with LIDATA records in OMF object files which always treated them as uninitialised data.

New features in v1.5:

* Added support for win32 COFF files
* Strips debug sections
* Added command-line setting of entry point
* Doesn't pad segments where unnecessary

New features in v1.4:

* Added support for resource files
* Added option to set subsystem/os version for PE output
* Added code to set time/date stamps for PE output
* Added POSIX subsystem option for PE output
* Native subsystem is known not to work, due to lack of checksum.
* Added support for COMDEF and BAKPAT OMF records to support MSVC 1.5

New features in v1.3:

* Added support for default libraries specified in object files
* Added library search path support
* Added native mode PE support
* Fixed some bugs in PE exports

New features in v1.2:

* Fixed 'disappearing data' bug when combining segments
* Fixed bug in fixup relocations when combining segments
* Fixed Import table bug (PE format)
* Fixed bug with groups from multiple object files

New features in v1.1:

* Fixed bug in PE output, which prevented files being loaded at addresses other than the image base
* Added support for user-specified stub files to PE output option

New features in v1.0:

* Now generates PE files for Win32.
* Can generate DLLs.
* Win32 import library provided.
* Lots of Win32 options command-line configurable.
* Fixed bug with self-relative fixups.
* Fixed bug with empty groups.

New features in v0.02:

* Now handles LIB files.
* Handles Imports/Exports. (But not supported by output formats!)
* Generates MAP file.

Version 0.01 features:

* Handles OBJ files.
* Generates COM files.
* Generates EXE files.
* Command line switch to choose whether to emit data for uninitialised segments.
* Case sensitivity supported.
12 changes: 12 additions & 0 deletions rtn.RC
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "windows.h"

AboutDlg DIALOG 10, 20, 170, 70
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Generic Win32 GUI Application"
FONT 10, "Arial"
BEGIN
DEFPUSHBUTTON "&Ok", IDOK, 60, 50, 40, 15
CTEXT "Sample GUI Application for NASM/ALINK", 101, 10, 10, 150, 8
CTEXT "A native Win32 executable", 102, 10, 20, 150, 8
END

68 changes: 68 additions & 0 deletions rtn.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
;NASM Win32 resource sample
; compile and link with
;
;nasm -fobj rtn.asm
;
;alink -oPE rtn win32.lib rtn.res


[extern DialogBoxParamA]
[extern GetModuleHandleA]
[extern ExitProcess]
[extern EndDialog]

WM_INITDIALOG equ 0110h
WM_COMMAND equ 0111h

IDOK equ 1

[segment code public use32 class='CODE']

..start:
enter 0,0
push byte 0
call GetModuleHandleA
mov [handle],eax
push byte 0
push dword DProc
push byte 0
push dword string
push byte 0
call DialogBoxParamA
push dword [handle]
call ExitProcess
leave
ret

DProc:
%define lparam ebp+20
%define wparam ebp+16
%define msg ebp+12
%define hdlg ebp+8
enter 0,0
mov eax,[msg]
cmp eax,WM_INITDIALOG
je @@wm_init
cmp eax,WM_COMMAND
je @@wm_command
@@unhandled:
xor eax,eax
leave
ret 16
@@wm_init:
mov eax,1
leave
ret 16
@@wm_command:
cmp dword [wparam],IDOK
jne @@unhandled
push byte 1
push dword [hdlg]
call EndDialog
mov eax,1
leave
ret 16

[segment data public]
handle dd 0
string db 'ABOUTDLG',0
Binary file added rtn.res
Binary file not shown.
36 changes: 36 additions & 0 deletions t2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
; t2.asm
; assemble with:
; nasm -fobj t2.asm
;
; link with
; alink -oPE t2
;
; run with
; t2
;
; expected output is four message boxes. First two say "Hello" in title
; last two say "Bye" in title
import start tdll.dll
import title1 tdll.dll
extern start
extern title1

segment code public use32 class=CODE

..start:
exestart:
call [start] ;display two message boxes
;need to call [start], since start gives address
;of Import Address Table entry, a pointer to routine

mov ebx,[title1] ;get address of title1 from IAT
mov [ebx],byte 'B'
mov [ebx+1],byte 'y'
mov [ebx+2],byte 'e'
mov [ebx+3],byte 0

call [start]

ret
Loading

0 comments on commit 702ab3f

Please sign in to comment.