flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 01 Jun 2010, 00:12
Code: ;File: assembly_a ;... public _my_symbol_from_a ;... ;File: assembly_b ;... public _my_symbol_from_b ;... ;File: assembly_both ;... extrn '_my_symbol_from_a' as _my_symbol_from_a extrn '_my_symbol_from_b' as _my_symbol_from_b ;... |
|||
![]() |
|
Trojany 02 Jun 2010, 02:22
Thanks, revolution,
but how'd you compile that? Code: ;File: source_a ;... Export my_symbol Export my_symbol_from_a ;Assume it's a different one, not a copy of my_symbol ;... ;File: source_b ;... Import my_symbol From "a/path/to/source_a" As my_symbol_from_a Export my_symbol ;... ;File: source_both ;... Import my_symbol_from_a From "a/path/to/source_a" As my_symbol_from_a Import my_symbol From "a/path/to/source_b" As my_symbol_from_b ;... Whenever there's function's or variable's definition in a source file, it's name is added to the file's local namespace, it doesn't interfere with a possibly same name in another source file. When functions or variables should be visible to other source files ("public"), the Export-statement is used - they're not added to a global namespace, they're just made visible, still in their local namespaces. When a source file needs to access a function or variable in another source, it uses the Import-statement, providing a (relative) path to the file, and the name which has been used when exporting the symbol. (that's the name in the other file's local namespace) The As-operator tells which name in the local namespace the symbol is to be imported to. |
|||
![]() |
|
revolution 02 Jun 2010, 04:44
Why not just avoid having the same named variables.
I always prefix the module name before each major label: Code: proc MODULE1_function
;...
endp
public MODULE1_function |
|||
![]() |
|
Tyler 02 Jun 2010, 05:08
Invent your own name mangling scheme. You could prepend the path to the file for example. http://en.wikipedia.org/wiki/Name_mangling
Fasm does this when you use the local directive in a macro. |
|||
![]() |
|
Trojany 04 Jun 2010, 02:22
Well, I hoped, there would be some option to specify what I want in the object files, maybe by creating the symbol tables manually instead of using format directive.
I thought these objected file formats, ELF or even COFF would have this feature, and it's just impossible to use it if you don't make the object file "from scratch" or use linker scripts. Otherwise yes, I'd have to do some name mangling, the problem with name mangling is that the object files can be distributed without source: so if someone receives somehow an object file and wants to use it without being able to recompile from source, the one has to stick to the symbol names in there. if these names collide with names in another object file received from another person, there's a problem. Appending local file paths to the symbol names wouldn't make them unique across a network. I think I'll have to make the compile query an UUID from OS an assign it to the module (using it as prefix for all symbols in its object file). |
|||
![]() |
|
Tyler 04 Jun 2010, 02:53
If you trust that every definition of the symbol that ld is reporting as being defined multiple times is referring to the same variable, you could use the "--allow-multiple-definition" option. It tells ld to ignore multiple definitions, and to the first definition it comes to for all references.
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.