English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 24 September 2013, 21:00   #1
dalton
tulou
 
dalton's Avatar
 
Join Date: Jun 2006
Location: Gothenburg / Sweden
Posts: 88
vasm dead code removal

Does anybody know if there is a way to tell vasm what code belongs to a specific routine? So that routines that are never called don't get included in the compiled exe.
dalton is offline  
Old 26 September 2013, 10:50   #2
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Unfortunately vasm cannot help you here. Is there a solution for that on other assemblers?

I would suggest to put your routines into a static linker library, so the linker (vlink) will only include those which are really needed. Use a separate object module for each routine to make it work.
phx is offline  
Old 26 September 2013, 12:35   #3
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
gcc has features (-ffunction-sections/-fdata-sections/-gc-sections) where it puts each function/data item in its own section and then the linker automatically discards unreferenced sections.. I know it's not vasm, but maybe of interest anyway..
hooverphonique is offline  
Old 26 September 2013, 13:06   #4
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by hooverphonique View Post
gcc has features (-ffunction-sections/-fdata-sections/-gc-sections) where it puts each function/data item in its own section
Indeed, but this will only work for a C source.
The assembler doesn't know where a function starts or ends, unless there is a directive which defines that.
phx is offline  
Old 26 September 2013, 16:53   #5
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by phx View Post
The assembler doesn't know where a function starts or ends, unless there is a directive which defines that.
you're right, of course.. my mind went wandering, I guess
hooverphonique is offline  
Old 27 September 2013, 08:01   #6
dalton
tulou
 
dalton's Avatar
 
Join Date: Jun 2006
Location: Gothenburg / Sweden
Posts: 88
Thanks for your replies!

Haven't seen any assembler which can do this. It would be a useful feature to have, as you could spend less time organizing routines into different files.

Perhaps not applicable to all types of code. But in most cases a function is just a function with a start and an end so syntactically it could be implemented with some kind of begin/end directives.

Last edited by dalton; 27 September 2013 at 08:22. Reason: manners
dalton is offline  
Old 27 September 2013, 10:59   #7
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by dalton View Post
Perhaps not applicable to all types of code. But in most cases a function is just a function with a start and an end so syntactically it could be implemented with some kind of begin/end directives.
Correct. That's what I was thinking. Then the assembler would only have to count the number of references to each label. When all labels between the start and end directive have zero references it is safe to discard the routine. Could be done...

EDIT: Maybe not that easy as I wrote first: References to labels between start and end from a location between the same start and end directives should not be counted, of course.

Last edited by phx; 27 September 2013 at 11:04. Reason: Thought about it again
phx is offline  
Old 27 September 2013, 15:16   #8
Apollo
Registered User
 
Apollo's Avatar
 
Join Date: Sep 2008
Location: Germany
Age: 49
Posts: 137
Does an assembler have an understanding of the program flow? For me this the difference with a higher languages compiler.
Apollo is offline  
Old 30 September 2013, 11:33   #9
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Apollo View Post
Does an assembler have an understanding of the program flow?
No, it has not.
But it can easily see whether a label is referenced from somewhere, while parsing operands.
phx is offline  
Old 30 September 2013, 11:44   #10
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Easily is relative I guess.

lea START-4(pc),a0
bsr GetHunk
; code to store hunk starts follows
...
; lots of other code
; a2: hunk starts
move.l (a2)+,d0
add.l #SOMECODE-STARTOFFSET,d0 ; label access, trivial?


etc. There are so many ways to disguise label referencing that I would not call it an easy task to detect any references.
StingRay is offline  
Old 30 September 2013, 12:40   #11
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Hm... you're right of course. Maybe I would have realized that when I started working on it.

It probably makes no sense to implement something like that into an assembler.
phx is offline  
Old 30 September 2013, 17:32   #12
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
In my opinion this is stuff for a HLL compiler anyway and neither needed nor required for assembler code as for asm the coder should take care of the code on his own.
StingRay is offline  
Old 01 October 2013, 08:12   #13
dalton
tulou
 
dalton's Avatar
 
Join Date: Jun 2006
Location: Gothenburg / Sweden
Posts: 88
Quote:
Perhaps not applicable to all types of code.
The use case I had in mind was when building some asm source together with a c source. The asm source would be fairly large and hold for instance routines for drawing different graphics primitives. Then I would like only the routines that are actually called from the c-context to be included in the exe.

For me it could be as simple as declaring that some asm-code should be left out if a specific label is never referenced.

Could look like this:

Code:
draw_line:

    IFREFERENCED draw_line

    ; awesome line drawing routine goes here
    rts

    ENDC
dalton is offline  
Old 01 October 2013, 10:23   #14
dalton
tulou
 
dalton's Avatar
 
Join Date: Jun 2006
Location: Gothenburg / Sweden
Posts: 88
Of course it would be good also to have a directive for explicitly referencing a label too. That can be used if you want to explicitly tell the assembler that you've referenced a label but the reference itself is hidden in trickery.
dalton is offline  
Old 01 October 2013, 11:49   #15
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by dalton View Post
Then I would like only the routines that are actually called from the c-context to be included in the exe.
Shouldn't the linker take care of that already?
StingRay is offline  
Old 01 October 2013, 12:23   #16
dalton
tulou
 
dalton's Avatar
 
Join Date: Jun 2006
Location: Gothenburg / Sweden
Posts: 88
As far as I understand, the linker cannot remove parts of an included asm source. To remove code you need to put each routine in a separate file and compile an object for each of them. Then only the objects that are used will be included.
dalton is offline  
Old 01 October 2013, 12:40   #17
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Your example to link with a C program looks like the ideal case for putting your assembler routines as separate objects into a static link library.

Why can't you do that? Maybe because your huge assembler source is already written and it is much work to divide it into small pieces?
phx is offline  
Old 01 October 2013, 14:31   #18
dalton
tulou
 
dalton's Avatar
 
Join Date: Jun 2006
Location: Gothenburg / Sweden
Posts: 88
Yes, this is typically how my legacy sources are organized. It is not incredibly hard to split them into many different files. But it's not much fun, and I guess that a feature like this could be useful also when coding pure asm.

I don't think there are any really convenient ways of maintaining function libraries in asm, and in the end the purpose of the assembler is to make life easier for us.
dalton is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Latest Win32 VASM Build? bodhi Coders. Asm / Hardware 89 25 August 2017 01:27
vasm and word alignment Den Coders. Asm / Hardware 9 07 February 2014 11:25
Help linking VASM object code clenched Coders. Asm / Hardware 2 24 May 2013 22:32
vasm fsincos dalton Coders. Asm / Hardware 4 03 September 2012 10:35
vasm 1.5 RFC phx Coders. General 30 11 December 2010 02:08

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 22:33.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09154 seconds with 13 queries