How can I specify linkinfo (things like Visual C __declspec(dllexport), __declspec(lib, "kernel32")) in MASM?
If you are creating a
.DLL file then you would:
- 1) Create a .DEF file (Definition file), and place the functions in that file you would like to export. Use the example I have created for you below.
- 2) Assemble your file(s).
- 3) When using LINK.EXE place this switch in there: /DEF:MyDefFileHere.DEF.
MyDefFileHere.DEFLIBRARY MyNewProgram
EXPORTS MyNewFunction
That's exactly what I am trying to get rid of. ;)
Are you are trying to remove kernel32 from your program?
I do not understand what you mean by 'trying to get rid of'.
I am trying to get rid of .DEF file in my project, by storing list of exported symbols in linkinfo section of object file.
In general, I am asking how to specify linkinfo for object files in MASM source.
Quote from: vid on August 11, 2010, 12:59:33 PM
I am trying to get rid of .DEF file in my project, by storing list of exported symbols in linkinfo section of object file.
It's possible to use the EXPORT attribute for procedures:
myproc proc EXPORT a1:dword
ret
myproc endp
this will make Masm add an entry "-export:_myproc@4" to the .drectve section, which is a section filled with "linker commands". It's slightly M$ proprietary.
Hey Japheth, good catch, this is what vid was looking for. I was trying to make the section manually, however, only MASM directive may start with dot so this doesn't work (and yes, the IMAGE_SCN_LNK_INFO attribute is missing, if it even can be forced in MASM):
.drectve SEGMENT
db "hello linker!"
.drectve ENDS
Do you know of any possibility how to create a section that starts with dot at MASM source code level?
Quote from: MazeGen on August 11, 2010, 02:18:54 PM
Hey Japheth, good catch, this is what vid was looking for.
How do you know that?
Quote
Do you know of any possibility how to create a section that starts with dot at MASM source code level?
I guess that's why the OPTION DOTNAME directive exists.
If you own
Masm v8+, you can even cause Masm set the info bit:
.drectve segment info
Quote from: japheth on August 11, 2010, 02:30:11 PM
Quote from: MazeGen on August 11, 2010, 02:18:54 PM
Hey Japheth, good catch, this is what vid was looking for.
How do you know that?
We've been chatting this in private today.
Quote from: japheth on August 11, 2010, 02:30:11 PM
Quote
Do you know of any possibility how to create a section that starts with dot at MASM source code level?
I guess that's why the OPTION DOTNAME directive exists.
If you own Masm v8+, you can even cause Masm set the info bit:
.drectve segment info
My bad, all you wrote is documented. Thanks for the information!
Damn! I didn't know you could place 'EXPORT' on a process! :clap: Very nice.
Thanks Japheth! Good to know new MASM supports making linkinfo section manually. In some cases I also like to add stuff like "/dll /entry:main kernel32.lib", not just list of exported funcs for DLL, but that was the main concern.
The cleanest way I found:
.686
.MODEL FLAT, STDCALL
OPTION DOTNAME
.drectve SEGMENT INFO DISCARD
db "/subsystem:console"
.drectve ENDS
.CODE
start:
int 3
END start
Two .drectve sections are made, the other is generated by MASM to propagate the entry point to linker. The linker obviously reads all the .drectve sections because I didn't get any errors.
Assemble and link it with just:
ml drectve.asm
I use MASM and LINK 9.00.30729.01.
The manual section has attributes different from the automatic one, but this doesn't seem to be an issue as well:
SECTION HEADER #3
.drectve name
0 physical address
0 virtual address
12 size of raw data
DD file pointer to raw data (000000DD to 000000EE)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
2000240 flags
Initialized Data
Info
Discardable
(no align specified)
RAW DATA #3
00000000: 2F 73 75 62 73 79 73 74 65 6D 3A 63 6F 6E 73 6F /subsystem:conso
00000010: 6C 65 le
Linker Directives
-----------------
/subsystem:console
SECTION HEADER #5
.drectve name
0 physical address
0 virtual address
D size of raw data
167 file pointer to raw data (00000167 to 00000173)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
A00 flags
Info
Remove
(no align specified)
RAW DATA #5
00000000: 2F 45 4E 54 52 59 3A 73 74 61 72 74 20 /ENTRY:start
Linker Directives
-----------------
/ENTRY:start
MS COFF Directive section creator (http://www.masm32.com/board/index.php?topic=6857.0)