From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1814) id 76FF93858296; Thu, 9 Mar 2023 15:00:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76FF93858296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678374050; bh=6qV32MtTVaI6josmj6sC5B2dU/aBqG6REq8If/3mbnw=; h=From:To:Subject:Date:From; b=cZddHp2l+BGmzJ1mhWlZXvkCkA3/3r1Y1/rDI/tnBWqDfC5GQdVdi8mpNTmyWXIYr EuJI/SOhNIMOPmDac53kiMvpHOLnsyRrPH12nmCXjF1kk9eK360eslNPVWA2DblreA 9b5ETx1f9NMu7s6zmwE/zqyeAO7yQomUiJJmJaxs= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Yong To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6552] Enable UTF-8 code page on Windows 64-bit host [PR108865] X-Act-Checkin: gcc X-Git-Author: Costas Argyris X-Git-Refname: refs/heads/master X-Git-Oldrev: a6457974a1f443ab58d2334c02260299616c78b8 X-Git-Newrev: d11e088210a551235d3937f867ee1c8b19d02290 Message-Id: <20230309150050.76FF93858296@sourceware.org> Date: Thu, 9 Mar 2023 15:00:50 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d11e088210a551235d3937f867ee1c8b19d02290 commit r13-6552-gd11e088210a551235d3937f867ee1c8b19d02290 Author: Costas Argyris Date: Tue Feb 28 17:10:18 2023 +0000 Enable UTF-8 code page on Windows 64-bit host [PR108865] Compile a resource object that contains the utf8 manifest. Then link that object into the driver and compiler proper. For compiler proper the link has to be forced because the resource object file gets into a static library (libbackend.a) and gets eventually dropped because it has no symbols of its own and nothing is referencing it inside the library. Therefore, an artificial symbol is planted to force the link. gcc/ChangeLog: PR driver/108865 * config.host: add object for x86_64-*-mingw*. * config/i386/sym-mingw32.cc: dummy file to attach symbol. * config/i386/utf8-mingw32.rc: windres resource file. * config/i386/winnt-utf8.manifest: XML manifest to enable UTF-8. * config/i386/x-mingw32: reference to x-mingw32-utf8. * config/i386/x-mingw32-utf8: Makefile fragment to embed UTF-8 manifest. Signed-off-by: Jonathan Yong <10walls@gmail.com> Diff: --- gcc/config.host | 5 ++-- gcc/config/i386/sym-mingw32.cc | 1 + gcc/config/i386/utf8-mingw32.rc | 3 ++ gcc/config/i386/winnt-utf8.manifest | 8 ++++++ gcc/config/i386/x-mingw32 | 3 +- gcc/config/i386/x-mingw32-utf8 | 56 +++++++++++++++++++++++++++++++++++++ 6 files changed, 72 insertions(+), 4 deletions(-) diff --git a/gcc/config.host b/gcc/config.host index a522c39658e..4abb32ad73d 100644 --- a/gcc/config.host +++ b/gcc/config.host @@ -241,10 +241,11 @@ case ${host} in x86_64-*-mingw*) use_long_long_for_widest_fast_int=yes host_xm_file=i386/xm-mingw32.h - host_xmake_file="${host_xmake_file} i386/x-mingw32" + host_xmake_file="${host_xmake_file} i386/x-mingw32 i386/x-mingw32-utf8" host_exeext=.exe out_host_hook_obj=host-mingw32.o - host_extra_gcc_objs="${host_extra_gcc_objs} driver-mingw32.o" + host_extra_objs="${host_extra_objs} utf8-mingw32.o" + host_extra_gcc_objs="${host_extra_gcc_objs} driver-mingw32.o utf8rc-mingw32.o" host_lto_plugin_soname=liblto_plugin.dll ;; aarch64*-*-darwin*) diff --git a/gcc/config/i386/sym-mingw32.cc b/gcc/config/i386/sym-mingw32.cc new file mode 100644 index 00000000000..f369698abc4 --- /dev/null +++ b/gcc/config/i386/sym-mingw32.cc @@ -0,0 +1 @@ +char HOST_EXTRA_OBJS_SYMBOL; diff --git a/gcc/config/i386/utf8-mingw32.rc b/gcc/config/i386/utf8-mingw32.rc new file mode 100644 index 00000000000..e2174e85b7c --- /dev/null +++ b/gcc/config/i386/utf8-mingw32.rc @@ -0,0 +1,3 @@ +#include + +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "winnt-utf8.manifest" diff --git a/gcc/config/i386/winnt-utf8.manifest b/gcc/config/i386/winnt-utf8.manifest new file mode 100644 index 00000000000..dab929e1515 --- /dev/null +++ b/gcc/config/i386/winnt-utf8.manifest @@ -0,0 +1,8 @@ + + + + + UTF-8 + + + diff --git a/gcc/config/i386/x-mingw32 b/gcc/config/i386/x-mingw32 index 5b8b5f96143..cb3d8434881 100644 --- a/gcc/config/i386/x-mingw32 +++ b/gcc/config/i386/x-mingw32 @@ -27,8 +27,7 @@ WERROR_FLAGS += -Wno-format host-mingw32.o : $(srcdir)/config/i386/host-mingw32.cc $(CONFIG_H) $(SYSTEM_H) \ coretypes.h hosthooks.h hosthooks-def.h toplev.h $(DIAGNOSTIC_H) $(HOOKS_H) - $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ - $(srcdir)/config/i386/host-mingw32.cc + $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< driver-mingw32.o : $(srcdir)/config/i386/driver-mingw32.cc $(CONFIG_H) $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< diff --git a/gcc/config/i386/x-mingw32-utf8 b/gcc/config/i386/x-mingw32-utf8 new file mode 100644 index 00000000000..6161dc23547 --- /dev/null +++ b/gcc/config/i386/x-mingw32-utf8 @@ -0,0 +1,56 @@ +# Copyright (C) 2023 Free Software Foundation, Inc. +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GCC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . +# +# +# For 64-bit Windows host, embed a manifest that sets the active +# code page of the driver and compiler proper processes to utf8. +# This only has an effect on Windows version 1903 (May 2019 Update) +# or later. + +# The resource .rc file references the utf8 .manifest file. +# Compile it into an object file using windres. +# The resulting .o file gets added to host_extra_gcc_objs in +# config.host for x86_64-*-mingw* host and gets linked into +# the driver as a .o file, so it's lack of symbols is OK. +utf8rc-mingw32.o : $(srcdir)/config/i386/utf8-mingw32.rc + $(WINDRES) $< $@ + +# Create an object file that just exports the global symbol +# HOST_EXTRA_OBJS_SYMBOL +sym-mingw32.o : $(srcdir)/config/i386/sym-mingw32.cc + $(COMPILER) -c $< $@ + +# Combine the two object files into one which has both the +# compiled utf8 resource and the HOST_EXTRA_OBJS_SYMBOL symbol. +# The resulting .o file gets added to host_extra_objs in +# config.host for x86_64-*-mingw* host and gets archived into +# libbackend.a which gets linked into the compiler proper. +# If nothing references it into libbackend.a, it will not +# get linked into the compiler proper eventually. +# Therefore we need to request the symbol at compiler link time. +utf8-mingw32.o : utf8rc-mingw32.o sym-mingw32.o + $(COMPILER) -r utf8rc-mingw32.o sym-mingw32.o -o $@ + +# Force compilers to link against the utf8 resource by +# requiring the symbol to be defined. +# Otherwise the object file won't get linked in the compilers +# because nothing is referencing it in libbackend.a +# This is expected because the resource object is not supposed +# to have any symbols, it just has to be linked into the +# executable in order for Windows to use the utf8 code page. +$(COMPILERS) : override LDFLAGS += -Wl,--require-defined=HOST_EXTRA_OBJS_SYMBOL