From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by sourceware.org (Postfix) with ESMTPS id 877AB3858D1E for ; Wed, 29 Mar 2023 13:36:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 877AB3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f46.google.com with SMTP id i5-20020a05600c354500b003edd24054e0so11470111wmq.4 for ; Wed, 29 Mar 2023 06:36:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680097003; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1G36zAb2qHgpwM47zvJH3OBlFicaDbJ/p89x6q4nj4c=; b=Lqk8gprWMmuhTEi0KVHeqH/6nqK/cD9xyNtHCY/HXM/7LCCJFebK6Iv+ZnzZSXMsMy naCQHgiXbAAQ7qMsOYFhdF7a/A78uKDFe2lY2MxCygOj3zoo3tmiYBelv9OkShe4GA/8 xJFBxAhvmmq1996kFWylBAzrMgLK/EtkPaoJgMoCKxLjEscT7iyuLUL3itk4FRiHoVma 9NqJEOZqQp6n+yeWfhUQxMnn/nOywqn9o9eCJkyZl7ntET3Mt/IuKgMiXdGM85W1p1Ax 92SKEUd3wswCovE3XRoMOqfkx5uP6/Ub6Vn79jKHlvyl3PPRpjKhBclqvMyDmqIJtWlJ FaTg== X-Gm-Message-State: AO0yUKX70DZrnbuPZ3Urv4uDGG8wVKzrwLUjWb6khkFDc03V5e40aQDN Ldn4inRRlytoUc9dkJX0ylzyj+/q2cCFdg== X-Google-Smtp-Source: AK7set+QI/ENC/LDs2XuQ8GWsOixXeLzyPLFIsrl3h+0/npnOO5/GwSXkaAMMe6C37WmSqZOqr1+yg== X-Received: by 2002:a05:600c:2046:b0:3e9:f15b:935b with SMTP id p6-20020a05600c204600b003e9f15b935bmr15548993wmg.32.1680097003065; Wed, 29 Mar 2023 06:36:43 -0700 (PDT) Received: from ?IPv6:2001:8a0:f93c:5900::1fe? ([2001:8a0:f93c:5900::1fe]) by smtp.gmail.com with ESMTPSA id iv19-20020a05600c549300b003ef69873cf1sm2543356wmb.40.2023.03.29.06.36.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Mar 2023 06:36:42 -0700 (PDT) Subject: Re: [PATCH] Modify align-c/align-c++ test case for AIX To: Aditya Kamath1 , Ulrich Weigand , "gdb-patches@sourceware.org" , "tom@tromey.com" Cc: Sangamesh Mallayya , "simon.marchi@efficios.com" References: <87edpwmzpz.fsf@tromey.com> <3636157c35660e96f2da98eb70cbac597d0a092c.camel@de.ibm.com> <87r0tqchea.fsf@tromey.com> <87zg8bave2.fsf@tromey.com> <61289f79c8c08ebe15112711954e1b05d49c92be.camel@de.ibm.com> <877cvagpeh.fsf@tromey.com> <82c24017291c399d58fc87d7ae7fc1b17c665295.camel@de.ibm.com> From: Pedro Alves Message-ID: Date: Wed, 29 Mar 2023 14:36:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-03-29 12:28 p.m., Aditya Kamath1 wrote: >>I'm wondering whether __attribute__((used)) on the global variable makes any >>difference.  IIRC with LLVM it prevents link-time stripping on Mach-O and PE/COFF, >>but I don't know about XCOFF + GCC.  (It doesn't on ELF, you >>need 'retain' for that.) > > Hi Pedro. So thanks for this suggestion. I learnt something new from you. But this __attribute__((used)) did not make any difference in our environment. Thanks for checking. I also recalled that Clang with LTO has a similar issue, and there __attribute__((used)) tends to help. Seems to me that it's best to tweak the code generator to just emit uses for all variables then, instead of special casing some platform or some specific variable. Like below. Does this work for AIX? >From 576c9c77ff3ac297a58662471fd0a2546a1d5f42 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 29 Mar 2023 13:21:20 +0100 Subject: [PATCH] Fix gdb.base/align-*.exp and Clang + LTO and AIX GCC Clang with LTO (clang -flto) garbage collects unused global variables, Thus, gdb.base/align-c.exp and gdb.base/align-c++.exp fail with hundreds of FAILs like so: $ make check \ TESTS="gdb.*/align-*.exp" \ RUNTESTFLAGS="CC_FOR_TARGET='clang -flto' CXX_FOR_TARGET='clang++ -flto'" ... FAIL: gdb.base/align-c.exp: get integer valueof "a_char" FAIL: gdb.base/align-c.exp: print _Alignof(char) FAIL: gdb.base/align-c.exp: get integer valueof "a_char_x_char" FAIL: gdb.base/align-c.exp: print _Alignof(struct align_pair_char_x_char) FAIL: gdb.base/align-c.exp: get integer valueof "a_char_x_unsigned_char" ... AIX GCC has the same issue, and there the easier way of adding __attribute__((used)) to globals does not help. So add explicit uses of all globals to the generated code. For the C++ test, that reveals that the static variable members of the generated structs are not defined anywhere, leading to undefined references. Fixed by emitting initialization for all static members. Lastly, I noticed that CXX_FOR_TARGET was being ignored -- that's because the align-c++.exp testcase is compiling with the C compiler driver. Fixed by passing "c++" as option to prepare_for_testing. Change-Id: I874b717afde7b6fb1e45e526912b518a20a12716 --- gdb/testsuite/gdb.base/align.exp.tcl | 49 ++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/gdb.base/align.exp.tcl b/gdb/testsuite/gdb.base/align.exp.tcl index 6a75a14d887..550afe1c47d 100644 --- a/gdb/testsuite/gdb.base/align.exp.tcl +++ b/gdb/testsuite/gdb.base/align.exp.tcl @@ -94,12 +94,15 @@ proc prepare_test_source_file { lang } { puts $outfile "DEF_WITH_1_STATIC ($utype, $uinner);" set joined "static_${utype}_x_${uinner}" puts $outfile "struct align_pair_$joined item_${joined};" + puts $outfile "$utype align_pair_${joined}::one = 0;" puts $outfile "unsigned a_${joined}" puts $outfile " = ${align_func} (struct align_pair_${joined});" puts $outfile "DEF_WITH_2_STATIC ($utype, $uinner);" set joined "static_${utype}_x_static_${uinner}" puts $outfile "struct align_pair_$joined item_${joined};" + puts $outfile "$utype align_pair_${joined}::one = 0;" + puts $outfile "$uinner align_pair_${joined}::two = 0;" puts $outfile "unsigned a_${joined}" puts $outfile " = ${align_func} (struct align_pair_${joined});" } @@ -107,12 +110,53 @@ proc prepare_test_source_file { lang } { } # Epilogue. - puts $outfile { + puts $outfile " int main() { - return 0; + " + + # Clang with LTO garbage collects unused global variables, even at + # -O0. Likewise AIX GCC. Add uses to all global variables to + # prevent it. + + if { $lang == "c" } { + puts $outfile "a_void++;" + } + + # First, add uses for single items. + foreach type $typelist { + set utype [join [split $type] _] + puts $outfile "item_$utype++;" + if { $lang == "c" } { + puts $outfile "a_$utype++;" + } + } + + # Now add uses for all pairs. + foreach type $typelist { + set utype [join [split $type] _] + foreach inner $typelist { + set uinner [join [split $inner] _] + set joined "${utype}_x_${uinner}" + puts $outfile "item_${joined}.one++;" + puts $outfile "a_${joined}++;" + + if { $lang == "c++" } { + set joined "static_${utype}_x_${uinner}" + puts $outfile "item_${joined}.one++;" + puts $outfile "a_${joined}++;" + + set joined "static_${utype}_x_static_${uinner}" + puts $outfile "item_${joined}.one++;" + puts $outfile "a_${joined}++;" + } } } + puts $outfile " + return 0; + } + " + close $outfile return $filename @@ -127,6 +171,7 @@ proc run_alignment_test { lang } { set flags {debug} if { "$lang" == "c++" } { + lappend flags "c++" lappend flags "additional_flags=-std=c++11" } standard_testfile $filename base-commit: b863b097ee7a79b1114b9dd386864bc3c23a51b0 -- 2.36.0