From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1698) id 0569D3858414; Thu, 25 Apr 2024 19:23:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0569D3858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714073001; bh=myfRP2XwT852V1rTdYWRM5TBm4QDzdtyeorLUwNyH1A=; h=From:To:Subject:Date:From; b=tRMwh1fWmQdqn8hXE16r/PCsOoFLn4Te2DTosgWLdJIOtVYXRa/qyt2s3Rzp8HlGq bIY81l7QBL2fktY/66p49r2G4FDmJcWLyoJiDNIxwmsbhRlvHWQn0i2N5SFuq95nPs uN3gh7Lq4ptV3klF9WY2EN9vxo8ERKr0X6JNoC20= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Iain D Sandoe To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-11370] Darwin, debug : Switch to DWARF 3 or 4 when dsymutil supports it. X-Act-Checkin: gcc X-Git-Author: Iain Sandoe X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 12ce016bc52f88ebaa085f2af14854247570cca7 X-Git-Newrev: 4805205720c5a3cd3997fb3d670f290856dba18d Message-Id: <20240425192321.0569D3858414@sourceware.org> Date: Thu, 25 Apr 2024 19:23:20 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4805205720c5a3cd3997fb3d670f290856dba18d commit r11-11370-g4805205720c5a3cd3997fb3d670f290856dba18d Author: Iain Sandoe Date: Sun Sep 17 15:56:07 2023 +0100 Darwin,debug : Switch to DWARF 3 or 4 when dsymutil supports it. The main reason that Darwin has been using DWARF2 only as debug is that earlier debug linkers (dsymutil) did not support any extensions to this so that the default "non-strict" mode used in GCC would cause tool errors. There are two sources for dsymutil, those based off a closed source base "dwarfutils" and those based off LLVM. For dsymutil versions based off LLVM-7+ we can use up to DWARF-4, and for versions based on dwarfutils 121+ we can use DWARF-3. Signed-off-by: Iain Sandoe gcc/ChangeLog: * config/darwin-protos.h (enum darwin_external_toolchain): New. * config/darwin.c (DSYMUTIL_VERSION): New. (darwin_override_options): Choose the default debug DWARF version depending on the configured dsymutil version. (cherry picked from commit 47346acb72b50d178dae72393c851d57beec383f) Diff: --- gcc/config/darwin-protos.h | 11 +++++++++++ gcc/config/darwin.c | 33 +++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h index f5ef82456aa..440e76ead42 100644 --- a/gcc/config/darwin-protos.h +++ b/gcc/config/darwin-protos.h @@ -129,4 +129,15 @@ extern void darwin_patch_builtins (void); extern void darwin_rename_builtins (void); extern bool darwin_libc_has_function (enum function_class fn_class, tree); +/* For this port, there are several possible sources for external toolchain + components (e.g. as, ld, dsymutil) and we have to alter the allowable + output in response to which version and source is in use. */ +enum darwin_external_toolchain { + DET_UNKNOWN=0, + CCTOOLS, + DWARFUTILS, + LLVM, + CLANG +}; + #endif /* CONFIG_DARWIN_PROTOS_H */ diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index db0e80889ab..e01460a996f 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -111,6 +111,19 @@ static bool ld_needs_eh_markers = false; /* Emit a section-start symbol for mod init and term sections. */ static bool ld_init_term_start_labels = false; +/* The source and version of dsymutil in use. */ +#ifndef DSYMUTIL_VERSION +# warning Darwin toolchain without a defined dsymutil. +# define DSYMUTIL_VERSION DET_UNKNOWN,0,0,0 +#endif + +struct { + darwin_external_toolchain kind; /* cctools, llvm, clang etc. */ + int major; /* version number. */ + int minor; + int tiny; +} dsymutil_version = {DSYMUTIL_VERSION}; + /* Section names. */ section * darwin_sections[NUM_DARWIN_SECTIONS]; @@ -3316,14 +3329,26 @@ darwin_override_options (void) global_options.x_flag_objc_abi); } - /* Don't emit DWARF3/4 unless specifically selected. This is a - workaround for tool bugs. */ + /* Limit DWARF to the chosen version, the linker and debug linker might not + be able to consume newer structures. */ if (!global_options_set.x_dwarf_strict) dwarf_strict = 1; + if (!global_options_set.x_dwarf_version) - dwarf_version = 2; + { + /* External toolchains based on LLVM or clang 7+ have support for + dwarf-4. */ + if ((dsymutil_version.kind == LLVM && dsymutil_version.major >= 7) + || (dsymutil_version.kind == CLANG && dsymutil_version.major >= 7)) + dwarf_version = 4; + else if (dsymutil_version.kind == DWARFUTILS + && dsymutil_version.major >= 121) + dwarf_version = 3; /* From XC 6.4. */ + else + dwarf_version = 2; /* Older cannot safely exceed dwarf-2. */ + } - if (global_options_set.x_dwarf_split_debug_info) + if (global_options_set.x_dwarf_split_debug_info && dwarf_split_debug_info) { inform (input_location, "%<-gsplit-dwarf%> is not supported on this platform, ignored");