Sujet : Re: question about linker
De : antispam (at) *nospam* fricas.org (Waldek Hebisch)
Groupes : comp.lang.cDate : 27. Nov 2024, 11:29:55
Autres entêtes
Organisation : To protect and to server
Message-ID : <vi6sb1$148h7$1@paganini.bofh.team>
References : 1
User-Agent : tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
Thiago Adams <
thiago.adams@gmail.com> wrote:
(I think I know the answer but I would like to learn more.)
I am using C89 as "compiler backend intermediate language".
I want a very simple output that could facilitate the construction of a
simple C89 compiler focused on code generation.
I am removing these features from the generated code.
- typedef
- enum
- preprocessor
- const
At this output, I am generating the prototypes for the functions I call.
For instance,
int strcmp( const char* lhs, const char* rhs );
is generated as
int strcmp( char* lhs, char* rhs );
I am also generating the structs as required (on demand). For the
structs I am renaming it because I am generating all structs at global
scope.
Question:
Does the compiler/linkers? Cares If I am lying about const? Or If rename
the structs?
1) campilers for embedded targets care very much about const. const
qualified arrays go into read-only data section which is typically
located in flash. Other arrays go to RAM. Embedded targets
frequently have very small RAM and larger flash, so after
dropping const program may no longer fit in available RAM.
2) Linkers for non-standard formats may do whatever they please. In
particular compiler could emit type information and linker may
check it.
3) If you want later C, then C89 as intermediate format will not
work, basically it is hard to implement VLA-s without VLA-s
in target language. In principle you can replace VMT-s by
pointer arithmetic, but then you have nontrivial chunk of
code generator inside your front end.
-- Waldek Hebisch