Page 1 of 1

namespaces in object files

Posted: Fri Mar 24, 2006 3:13 am
by octavio
Some programming languages support multiple namespaces
with composite names for example:
c: n1.n2.n3 n1->n2->n3
c#: n1::n2::n3
octasm: n1\n2\n3
but they use different syntaxes, since the object files like
elf should be language independent for linking modules writting
in different languages, is there a standard way of doing it?
i have read the Elf format specification and it seems that only
a single flat namespace is supported.

Re:namespaces in object files

Posted: Fri Mar 24, 2006 3:27 am
by Solar
Short answer: No, there's no standard way to do it.

Long answer:

To my knowledge, there is no inter-language-support inherent in the ELF specification.

And what you quote for C isn't "namespaces", it's a struct within a struct within a struct - quite a different thing, because adding elements to n1 makes n1 take up more memory, which isn't very namespace-like.

C++ uses name mangling, which is specific to C++ only IIRC.

C# targets the Microsoft CLI, which hasn't anything to do with ELF.

There is no standard to bring all languages together. There are several attempts - MS CLI, swig, CORBA, all with different focus and with their pro's and con's.

ELF is simply how you put code, data, and symbols into a file, and doesn't know much about the languages you use.

Re:namespaces in object files

Posted: Fri Mar 24, 2006 10:41 am
by octavio
about the inter-language-support i mean that it?s possible to link two object (obj elf etc...) files made with different compilers, else object files would be pretty useless.
Thats the reason i want to add support for ELF files to my assembler.
And there should be some way for a C compiler to put a member of a struct inside a object file,but since there is no standard perhaps is the moment to create one, some suggestions...?
I don?t know the official definition of namespace, for me is just the posibility of using the same names in different parts of
a program without the problem of name colisions, like filenames in a hierarchical filesystem.

Re:namespaces in object files

Posted: Fri Mar 24, 2006 11:29 am
by Solar
octavio wrote: about the inter-language-support i mean that it?s possible to link two object (obj elf etc...) files made with different compilers, else object files would be pretty useless.
You have rather optimistic expectations on object files. The C++ ABI is a rather new thing - before that, linking object files from different compilers did not work flawlessly, even within the very same language...
Thats the reason i want to add support for ELF files to my assembler.
ELF is a standard for linkers and loaders. It does not improve interoperability between languages.

The fact that ASM, C and - to a more limited extend - C++ interoperate so well is due to the design of the respective languages.
And there should be some way for a C compiler to put a member of a struct inside a object file,but since there is no standard perhaps is the moment to create one, some suggestions...?
I honestly have no idea what you're talking about...? Of course a struct member is inside an object file... *[me=Solar]bewildered*[/me]
I don?t know the official definition of namespace, for me is just the posibility of using the same names in different parts of
a program without the problem of name colisions, like filenames in a hierarchical filesystem.
Uh, oh... perhaps you want to learn about "identifier scopes" first... exactly from where to where a variable / function name is valid, given the modifiers that C and C++ offer (static, extern, auto...)

Re:namespaces in object files

Posted: Tue Mar 28, 2006 2:20 pm
by Schol-R-LEA
I have the sinking feeling that Octavio is having a hash collision on the term 'object'. Object files have nothing to with objects in the paradigmatic sense; they are a representation of the executable code produced by the compiler or assembler, with the absolute addresses and external references replaced with placeholders which the linker can patch with the actual values when the separate files are combined into the final executable (though the final step of assigning actual address references is usually held up until loading).

For more details on object formats, and ELF inparticular, see the online version of Linkers and Loaders by John Levine.