Author Topic: How to use ld.exe to link Hello World without using libraries/luser32?  (Read 33283 times)

Offline frankly

  • Jr. Member
  • *
  • Posts: 21
Re: How to use ld.exe to link Hello World without using libraries/luser32?
« Reply #15 on: September 03, 2018, 02:55:36 AM »

On August 19, 2018, 10:39:51 PM Frankly replied -
Quote
However there seems to be a few differences between using ld.exe and using GoLink.exe -
The resulting Hello2.exe file after the ld linking is a bloated 3535 Bytes compared to Hello1.exe size of 1536 bytes from GoLink.
Also the ld Hello2.exe throws up a Command Line window/shell along with the Output Window where the GoLink Hello1.exe only displays the Output Window.

On September 02, 2018, 05:38:22 PM stressful replied -
Quote
;ld -m i386pe this.obj -subsystem windows {path to user32.dll} {path to kernel32.dll} -o this.exe (for Win32 subsystem)

@stressful -
I just used your modified version of the ld command line (for win32 subsystem) on my original Hello2.obj file and the resulting Hello2.exe file no longer throws up a Command Line window/shell along with the Output Window!

Thank you for showing me that!  I will have to read more about ld's -m i386pe option and the -subsystem windows option.

Unfortunately, even after using your modified ld command line the resulting Hello2.exe file still is a bloated 3535 Bytes compared to GoLink's Hello2.exe file of 1536 Bytes.  I am hoping to read more (when I have the time) about the ld linker to see if there is a command line option to slim the resulting bloated Hello2.exe file down to GoLink's size.

 -Frankly

Offline frankly

  • Jr. Member
  • *
  • Posts: 21
Re: How to use ld.exe to link Hello World without using libraries/luser32?
« Reply #16 on: September 03, 2018, 02:32:32 PM »
On August 19, 2018, 10:39:51 PM Frankly replied -
Quote
The resulting Hello2.exe file after the ld linking is a bloated 3535 Bytes compared to Hello1.exe size of 1536 bytes from GoLink.

After further reading of the different versions of ld.exe manuals I found the ld.exe option '--strip-all' in ld.exe version 2.28 which removes all symbols from ld's exe file output.

So after updating my ld.exe to version 2.28 and running this command line (thanks again to 'stressful' for the -m and -subsystem suggestions)...
Code: [Select]
ld.exe --strip-all -m i386pe Hello2.obj -subsystem windows C:\WINDOWS\system32\user32.dll -o C:\Hello2.exe
...the resulting Hello2.exe file is now 1536 Bytes - JUST like the resulting Hello2.exe file from my GoLink.exe version 0.2.5.4!

I have included this latest Hello2.exe(Hello2.zip) file for anyone that wishes to analyze it.
EDIT - I accidently modified my Hello2.asm code a little (I changed the Window Title and the message now says 'Hello2!' instead of 'Howdy') however the file itself is basically the same.  (I do not have the moderator capablitiles to delete uploaded files so I could not fix this myself)
« Last Edit: September 03, 2018, 02:53:28 PM by frankly »

Offline stressful

  • Full Member
  • **
  • Posts: 105
  • Country: 00
    • CPU2.0
Re: How to use ld.exe to link Hello World without using libraries/luser32?
« Reply #17 on: September 04, 2018, 07:07:26 PM »
Glad I helped u in some way and thanks for sharing your solution.

Personally, I do not recommend using anything *nixy on Windows, especially the binutil toolchains. For Win32 systems, I'd go for tools like GoLink, MS-LINK or something similar. "ld" and the entire binutils toolchain are quite messy once emulated on windows. "ld" would probably end up calling m$ kernel services anyway. Just my 2 cents worth.