From f8eb5f4ab8c672c85c5c6aefc70344ec2cffab74 Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Sat, 16 Aug 2025 18:29:19 +0200 Subject: [PATCH] Add -znodelete linker option This option is needed for openssl to create a correct library. --- libtcc.c | 2 ++ tcc.h | 1 + tccelf.c | 2 ++ 3 files changed, 5 insertions(+) diff --git a/libtcc.c b/libtcc.c index 3f5ccbc4..ce3ac72a 100644 --- a/libtcc.c +++ b/libtcc.c @@ -1457,6 +1457,8 @@ static int tcc_set_linker(TCCState *s, const char *optarg) s->filetype |= AFF_WHOLE_ARCHIVE; } else if (link_option(&o, "no-whole-archive")) { s->filetype &= ~AFF_WHOLE_ARCHIVE; + } else if (link_option(&o, "znodelete")) { + s->znodelete = 1; #ifdef TCC_TARGET_PE } else if (link_option(&o, "large-address-aware")) { s->pe_characteristics |= 0x20; diff --git a/tcc.h b/tcc.h index f2b0dada..19e16625 100644 --- a/tcc.h +++ b/tcc.h @@ -741,6 +741,7 @@ struct TCCState { unsigned char static_link; /* if true, static linking is performed */ unsigned char rdynamic; /* if true, all symbols are exported */ unsigned char symbolic; /* if true, resolve symbols in the current module first */ + unsigned char znodelete; /* Set DF_1_NODELETE in dynamic section */ unsigned char filetype; /* file type for compilation (NONE,C,ASM) */ unsigned char optimize; /* only to #define __OPTIMIZE__ */ unsigned char option_pthread; /* -pthread option */ diff --git a/tccelf.c b/tccelf.c index edf4c4bb..b9944944 100644 --- a/tccelf.c +++ b/tccelf.c @@ -2939,6 +2939,8 @@ static int elf_output_file(TCCState *s1, const char *filename) put_dt(dynamic, DT_TEXTREL, 0); if (file_type & TCC_OUTPUT_EXE) dt_flags_1 = DF_1_NOW | DF_1_PIE; + if (s1->znodelete) + dt_flags_1 |= DF_1_NODELETE; } put_dt(dynamic, DT_FLAGS, DF_BIND_NOW); put_dt(dynamic, DT_FLAGS_1, dt_flags_1);