From 4e568451bface5d15fc0bb28bc6794612f32677c Mon Sep 17 00:00:00 2001 From: Robert Dubner Date: Thu, 24 Jul 2025 12:09:36 -0400 Subject: [PATCH] cobol: Honor the "-static" command-line option. [PR119231] gcc/cobol/ChangeLog: PR cobol/119231 * gcobolspec.cc: (lang_specific_driver): Pass OPT_static through. Handle -static and -static-libgcobol properly. gcc/testsuite/ChangeLog: * cobol.dg/group2/_-static__compilation.cob: Modify for -static warning. * cobol.dg/group2/_-static__compilation.out: Removed. (cherry picked from commit 44e32178031e89399710c3ee7444891631a9c8ec) --- gcc/cobol/gcobolspec.cc | 13 +++++++++++-- .../cobol.dg/group2/_-static__compilation.cob | 4 ++-- .../cobol.dg/group2/_-static__compilation.out | 2 -- 3 files changed, 13 insertions(+), 6 deletions(-) delete mode 100644 gcc/testsuite/cobol.dg/group2/_-static__compilation.out diff --git a/gcc/cobol/gcobolspec.cc b/gcc/cobol/gcobolspec.cc index 9532d4256b2..2f3092da5d8 100644 --- a/gcc/cobol/gcobolspec.cc +++ b/gcc/cobol/gcobolspec.cc @@ -478,7 +478,10 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, //// break; ////#endif case OPT_static: +#if defined (HAVE_LD_STATIC_DYNAMIC) + append_arg(decoded_options[i]); static_in_general = true; +#endif break; default: @@ -506,17 +509,23 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options, need_libgcobol = false; } + if( static_in_general ) + { + // These two options interfere with each other. + static_libgcobol = false; + } + if( need_libgcobol ) { add_arg_lib(COBOL_LIBRARY, static_libgcobol); } if( need_libdl ) { - add_arg_lib(DL_LIBRARY, static_in_general); + add_arg_lib(DL_LIBRARY, false); } if( need_libstdc ) { - add_arg_lib(STDCPP_LIBRARY, static_in_general); + add_arg_lib(STDCPP_LIBRARY, false); } if( prior_main ) diff --git a/gcc/testsuite/cobol.dg/group2/_-static__compilation.cob b/gcc/testsuite/cobol.dg/group2/_-static__compilation.cob index 7843d3d27aa..f344a84c398 100644 --- a/gcc/testsuite/cobol.dg/group2/_-static__compilation.cob +++ b/gcc/testsuite/cobol.dg/group2/_-static__compilation.cob @@ -1,7 +1,7 @@ *> { dg-do run } *> { dg-options "-static" } - *> { dg-output-file "group2/_-static__compilation.out" } - + *> { dg-prune-output {warning} } + *> { dg-output {hello, world} } IDENTIFICATION DIVISION. PROGRAM-ID. prog. PROCEDURE DIVISION. diff --git a/gcc/testsuite/cobol.dg/group2/_-static__compilation.out b/gcc/testsuite/cobol.dg/group2/_-static__compilation.out deleted file mode 100644 index ae0e5111cae..00000000000 --- a/gcc/testsuite/cobol.dg/group2/_-static__compilation.out +++ /dev/null @@ -1,2 +0,0 @@ -hello, world - -- 2.47.2