From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by sourceware.org (Postfix) with ESMTPS id 91B3C3857C5F for ; Tue, 1 Feb 2022 00:22:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 91B3C3857C5F Received: by mail-qv1-xf36.google.com with SMTP id h16so14473726qvk.10 for ; Mon, 31 Jan 2022 16:22:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RmxA1clPRZ9N86zUm0WQBOtNEf8wzTgXr/fAKI2AiVw=; b=omPkxloEl7Mi8Dr3g5bMY6Ep6VI10r+F6uA9YpcrUdCw4G3/hmNXMn1zzasHEjszdB ZbVCWo+4IrDnfx3qdUkU3wfAJLnQTHySfvSwAZCXi8JJql/mwHL2fmhlJUwEGZORpAJ0 Z4mRZciDEWm2zNOmaM7olfngr956azGH/pjIJ8B27HDloU/NVmCte63nCqANNBqg+DNN e/vwdigx6fjakjjUUlkATsD8SuKWlQLU62WeLoZjdtzaHWkxvcLjfviwLOsVntK3bYwd /kRSpqmiJH51XL+D2VMWXeoZi6tlnVTyxraYNbEyhQFrNspSo5pFoDpNsUM90kOhMsdU wQLw== X-Gm-Message-State: AOAM530EiwOxnCjnnAiWdZV6dDNer0DcTdY+qK+f3mNcegzRVmouWR1r DqcO1ihi+oRMyQiq71k7bIsCPB7vtw== X-Google-Smtp-Source: ABdhPJzmKF7uDkZahVfg/ZJgMF881x1LYClso/SJK2AqKhfPKQO1MJYlk69yYJNnAZ+cfjGAnM23qA== X-Received: by 2002:a05:6214:20af:: with SMTP id 15mr19702926qvd.105.1643674928007; Mon, 31 Jan 2022 16:22:08 -0800 (PST) Received: from bytedance.attlocal.net (ec2-52-52-7-82.us-west-1.compute.amazonaws.com. [52.52.7.82]) by smtp.gmail.com with ESMTPSA id az34sm3452449qkb.41.2022.01.31.16.22.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 16:22:07 -0800 (PST) From: Peilin Ye To: binutils@sourceware.org Cc: Nick Clifton , Alan Modra , Cong Wang , Peilin Ye , Peilin Ye Subject: [PATCH v3 2/2] binutils/testsuite: Test --only-keep-debug for ELF relocatables Date: Mon, 31 Jan 2022 16:21:55 -0800 Message-Id: <20220201002155.70518-1-yepeilin.cs@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220128230030.67552-1-yepeilin.cs@gmail.com> References: <20220128230030.67552-1-yepeilin.cs@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2022 00:22:09 -0000 From: Peilin Ye Recently we fixed a bug in objcopy's --only-keep-debug option for ELF relocatables. Add a test for it. binutils/ChangeLog: * testsuite/binutils-all/objcopy.exp (keep_debug_symbols_for_elf_relocatable): Test --only-keep-debug marks non-debug output sections as NOBITS for ELF relocatables Signed-off-by: Peilin Ye --- Hi all, Please review, thanks! binutils/testsuite/binutils-all/objcopy.exp | 57 +++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp index bb80c1f0b554..3dbb512b69cf 100644 --- a/binutils/testsuite/binutils-all/objcopy.exp +++ b/binutils/testsuite/binutils-all/objcopy.exp @@ -967,6 +967,60 @@ proc keep_debug_symbols_and_check_links { prog flags test } { } } +# For ELF relocatables, test that --only-keep-debug +# marks non-debug output sections as NOBITS. + +proc keep_debug_symbols_for_elf_relocatable { prog flags test } { + global srcdir + global subdir + global READELF + + if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { + untested $test + return + } + + if [is_remote host] { + set relocatable [remote_download host tmpdir/testprog.o] + } else { + set relocatable tmpdir/testprog.o + } + + set non_debug_sections {} + set got [binutils_run $READELF "-S --wide ${relocatable}"] + while { [regexp \ + {[^a-zA-Z]+([a-zA-Z0-9_\.]+)[ \t]+([A-Z]+)[ \t]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9]+[ \t]+([A-Z]*)[ \t]+[0-9]+(.*)} \ + $got all name type flag rest] } { + if { $type != "NOTE" && [regexp {[AG]} $flag] } { + lappend non_debug_sections $name + } + set got $rest + } + + set exec_output [binutils_run $prog "$flags ${relocatable}"] + if ![string equal "" $exec_output] { + fail $test + return + } + + set fails 0 + set got [binutils_run $READELF "-S --wide ${relocatable}"] + while { [regexp \ + {[^a-zA-Z]+([a-zA-Z0-9_\.]+)[ \t]+([A-Z]+)[ \t]+[0-9a-f]+ [0-9a-f]+ [0-9a-f]+ [0-9]+[ \t]+[A-Z]*[ \t]+[0-9]+(.*)} \ + $got all name type rest] } { + if { [lsearch -exact $non_debug_sections $name] >= 0 && $type != "NOBITS" } { + set fails 1 + send_log "Expected SHT_NOBITS type for .$name\n" + } + set got $rest + } + if { $fails == 1 } { + fail $test + return + } + + pass $test +} set test1 "simple objcopy of executable" set test1r "run objcopy of executable" @@ -978,6 +1032,7 @@ set test4 "keep only debug data" set test5 "simple objcopy of debug data" if [is_elf_format] { set test6 "NOBITS sections retain sh_link field" + set test7 "--only-keep-debug for ELF relocatables" } switch [copy_setup] { @@ -1008,6 +1063,7 @@ switch [copy_setup] { "$OBJCOPY" "$OBJCOPYFLAGS" "$test5" if [is_elf_format] { keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test6" + keep_debug_symbols_for_elf_relocatable "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test7" } } "0" { @@ -1018,6 +1074,7 @@ switch [copy_setup] { "$OBJCOPY" "$OBJCOPYFLAGS" "$test5" if [is_elf_format] { keep_debug_symbols_and_check_links "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test6" + keep_debug_symbols_for_elf_relocatable "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test7" } } } -- 2.20.1