Relative imports and GNU linker... ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello, gcc-community!

I'm currently planning to implement a new programming language as a
gcc-compatible compiler. More precisely: The program I'd like to develop
will get a source file of that new language as input, and will output an
object file which in turn can be linked by gnu linker (ld). I prefer this
way to other ways of developing a compiler (e.g. writing a program which
does all of the compilation process, from source file to target's executable
file format, itself, without using gnu linker), because it makes it easier
to link components written in that new language together with components
written in other languages, like C/C++/Java.

Since the creation of object files looked not that easy to me, I decided
that the compiler will only produce assembly code and use an assembler to
convert it to the actual object file. So the whole compiling process will
consist of
1.: pass each source file to the compiler which will produce assembly for
each source,
2.: pass each assembly code to the assembler (it'll use fasm) which will
produce the object files, and
3.: call the gnu linker once to link all the object files together.

My problem is:

That new language has a feature which I'm not sure about whether and how it
can be done with gnu linker:
In that language it is allowed, when importing symbols from other source
files, to explicitly specify which imported symbol comes from which source
file.
This means that it is possible to have the following three source files
built together to one program:

File: source_a
[begin of file's contents]
...
Export my_symbol
...
[end of file]

File: source_b
[begin of file's contents]
...
Export my_symbol
...
[end of file]

File: source_both
[begin of file's contents]
...
Import my_symbol 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
...
[end of file]

In that programming language this will NOT produce a compiling error, it is
allowed to have symbols with identical names defined in multiple source
files.
It will not produce a duplicate-identifier compile time error, because the
"As" operator was used in the import statements.
In the "source_both" file you can use my_symbol_from_a or my_symbol_from_b
to address my_symbol in source_a or source_b, respectively.

Now I'm thinking about how to compile such source files to object files
which in turn can be linked correctly with gnu linker.

A first attempt would be producing the following assembly files: (I use flat
assembler)

File: assembly_a
[begin of file's contents]
...
public _my_symbol
...
[end of file]

File: assembly_b
[begin of file's contents]
...
public _my_symbol
...
[end of file]

File: assembly_both
[begin of file's contents]
...
extrn _my_symbol??
extrn _my_symbol??
...
[end of file]

This won't work, because
1.: gnu linker prints "multiple definition of `my_symbol'" and returns with
an error, and
2.: I don't know how to specify which of the extrn _my_symbol statements is
to import from which other object file.
But how else could I create the object files?

I know that this behaviour of the language is somewhat different to that
other languages have, e.g. in C/C++ you just do declarations of extern
functions (by including the header files), without explicitly specifying
which function comes from which other source file. However, I'd still like
to find a way to use gnu linker as the last step of compiling programs in
that language.

Any help is appreciated, thanks in advance!

Sincerely,
Trojany
-- 
View this message in context: http://old.nabble.com/Relative-imports-and-GNU-linker...---tp28712872p28712872.html
Sent from the gcc - Help mailing list archive at Nabble.com.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux