[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain
From: |
YX Hao |
Subject: |
Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain |
Date: |
Tue, 12 Aug 2014 22:29:04 +0800 |
Hi gr and there,
What about like this?
And is my last email to Alex lost? I haven't received it.
Here it is:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hello,
For my last git commit file attached, the following patch for "tccelf.c" is
not neccessary as the Unicode entries have been placed into seperate crt
source files.
-----------------------------------------------------------------------------
diff --git a/tccelf.c b/tccelf.c
index 2fbe692..353f30d 100644
--- a/tccelf.c
+++ b/tccelf.c
@@ -2515,6 +2515,14 @@ typedef struct SectionMergeInfo {
uint8_t link_once; /* true if link once section */
} SectionMergeInfo;
+#ifdef TCC_TARGET_PE
+#ifdef TCC_TARGET_X86_64
+#define PE_STDSYM(n,s) n
+#else
+#define PE_STDSYM(n,s) "_" n s
+#endif
+#endif
+
/* load an object file and merge it with current files */
/* XXX: handle correctly stab (debug) info */
ST_FUNC int tcc_load_object_file(TCCState *s1,
@@ -2731,6 +2739,17 @@ ST_FUNC int tcc_load_object_file(TCCState *s1,
}
/* add symbol */
name = (char *) strtab + sym->st_name;
+#ifdef TCC_TARGET_PE
+ /* skip unused (undefined) */
+ int unicode_entry = s1->unicode_entry;
+ if ((unicode_entry == 3 /*PE_EXE*/ && strcmp(name, "main") != 0)
+ || (unicode_entry == 2 /*PE_GUI*/
+ && strcmp(name, PE_STDSYM("WinMain","@16")) != 0)
+ || (unicode_entry == 0
+ && strcmp(name, "wmain") != 0
+ && strcmp(name, PE_STDSYM("wWinMain","@16")) != 0)
+ )
+#endif
sym_index = add_elf_sym(symtab_section, sym->st_value,
sym->st_size,
sym->st_info, sym->st_other,
sym->st_shndx, name);
-----------------------------------------------------------------------------
So, the key is in "tccpe.c" to asign a proper entry. And, for optional, add
a gloabal flag "unicode_entry" as "TCC_TARGET_PE" for benching, in
"tccgen.c", "libtcc.c" and "tcc.h". It could not be neccesary.
We all must add the crt entry functions for Unicode. And I recommend put
them in new files, for smaller linked executable file.
From: Alexander De Sousa
It was only preliminary support for command line applications (no proper
tests), adding support for GUI applications would follow the same scheme.
Some thoughts on the matter:
- Separated startup code for Unicode entry points seem to be a must, <-- I
agree.
I couldn't find any way of doing it using the current crt1 and wincrt1.
- Third patch in a nutshell: check whether the wmain symbol is defined or
not and choose the Unicode start point if it is, the appropriate startup is
added through add_elf_sym and friends. <--- There is "find_elf_sym" can be
used.
- I didn't realize at the time, but the pe_is_unicode() function I defined
could be replaced for a call to find_elf_sym. <--- I think so.
- Since Unicode builds are actually triggered by the _UNICODE macro being
defined, an Unicode build could probably be identified already when the
macro is detected to be defined. Maybe activating a flag at that point
instead of looking for wmain or wWinMain when adding the startup code. <---
What if "_UNICODE" is NOT defined but directly use "wmain" or "wWinMain"? :)
Committing the second patch is probably a good idea regardless of Unicode
support being added, I think it helps maintainability. <--- I just try to
keep the same style. ^_^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Regards,
Yuxi Hao
----- Original Message -----
From: "grischka" <address@hidden>
To: <address@hidden>
Sent: Tuesday, August 12, 2014 9:15 PM
Subject: Re: [Tinycc-devel] Win: Add Unicode support for _tmain and
_tWinMain
Alexander De Sousa wrote:
Some thoughts on the matter:
- Separated startup code for Unicode entry points seem to be a must, I
couldn't find any way of doing it using the current crt1 and wincrt1.
I'd agree with separate code, but not with separate sources. Rather
it should work like this:
tcc -c crt1.c -o crt1.o
tcc -c crt1.c -D_UNICODE -o wcrt1.o
ar rcs libtcc1.a crt1.o wcrt1.o ...
After all that's the point of the _T/_t macros defined in tchar.h
and all the redirections in windows.h that depend on UNICODE.
-- gr
Regards,
Alex.
commit-d0b5a35.patch
Description: Binary data
- [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain, YX Hao, 2014/08/10
- Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain, Alexander De Sousa, 2014/08/12
- Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain, grischka, 2014/08/12
- Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain, YX Hao, 2014/08/12
- Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain,
YX Hao <=
- Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain, YX Hao, 2014/08/12
- Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain, grischka, 2014/08/12
- Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain, YX Hao, 2014/08/13
- Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain, grischka, 2014/08/15
- Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain, YX Hao, 2014/08/16
- Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain, Alexander De Sousa, 2014/08/16
- Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain, grischka, 2014/08/16
- Re: [Tinycc-devel] Win: Add Unicode support for _tmain and _tWinMain, YX Hao, 2014/08/17