From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by sourceware.org (Postfix) with ESMTPS id 8643A3858D28 for ; Sat, 29 Jan 2022 07:45:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8643A3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=maskray.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f179.google.com with SMTP id i186so5757691pfe.0 for ; Fri, 28 Jan 2022 23:45:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=3lGsxdeas1hDFLXgI+JgjwQZXTvr8YwX3+kXCy20tOU=; b=gfU8qy7NOB9uRXEoc1kRKo831fw95jx9D24owAcS/ltA54gmQ+hOllbfrrVKFOxeQz zbrHYvRjWQvjeAEH9d+2mSL1NQ0lMzPhLokIixf5MwKvElMs2g3t1RoLKbtYFSySo05D ca3NzX2904b7iX1tKrBKGfs7D3cTz+ucb5K+Yb4klAX2GN0X0bHu25h0iTK/9BJZuxxk 26WLkiVj1Dvg1End9oPaxDuXz/hXdzIpMde6yK0h579FsIrjKpKWDJ1ebFIbi/EHhIQ3 hAD9OX104Lya804t+yaN09324opepr0oTR4z2uPilEVPopmS4fYkL4pE26Qy2W6sh+tb Vscw== X-Gm-Message-State: AOAM5336p45IngiN/JzT3/XKVXyvILfnoWL2dgoGvfrF8m18BComGaIg IKYL6EjWL3s+FnMOGywG+xU= X-Google-Smtp-Source: ABdhPJwVP9x0H7GyOdAFSpfWfYi2h+9+pF1G4/POeSVLy+PgFR3F1kryPAlAIGPBt0Ac/EOmUtm35Q== X-Received: by 2002:a65:6093:: with SMTP id t19mr9323972pgu.584.1643442346551; Fri, 28 Jan 2022 23:45:46 -0800 (PST) Received: from localhost ([2601:647:6300:b760:2aaf:bc70:67e7:6a5e]) by smtp.gmail.com with ESMTPSA id k15sm11821195pff.39.2022.01.28.23.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jan 2022 23:45:46 -0800 (PST) Date: Fri, 28 Jan 2022 23:45:45 -0800 From: Fangrui Song To: Alan Modra , Nick Clifton Cc: binutils@sourceware.org, Luca Boccassi Subject: Output section type (READONLY) Message-ID: <20220129074545.csaig4kn5bk4si5k@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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: Sat, 29 Jan 2022 07:45:49 -0000 [PATCH v2] ld: add READONLY attribute for SECTIONS (https://sourceware.org/pipermail/binutils/2021-July/117492.html) added READONLY. There was no justification as to why it was added. It was presumably to make an output section non-writable by default. But for % cat output-section-types.t SECTIONS { .rom (NOLOAD) : { LONG(1234); } .ro (READONLY) : { LONG(5678); } .over (OVERLAY) : { LONG(0123); } /DISCARD/ : { *(*) } } .ro does not have the SHF_WRITE flag even without (READONLY). The unneeded SHF_WRITE flag has been fixed by Alan for https://sourceware.org/bugzilla/show_bug.cgi?id=26378#c11 . --- Well, READONLY has another behavior that it forces non-SHF_WRITE output even if an input section has the SHF_WRITE flag. % cat output-section-types.t SECTIONS { .rom (NOLOAD) : { LONG(1234); } .ro (READONLY) : { LONG(5678); *(.ro) } .over (OVERLAY) : { LONG(0123); } /DISCARD/ : { *(*) } } % cat x.s .section .ro,"aw" .quad 0 The output .ro does not have SHF_WRITE. There is no warning. [ 2] .ro PROGBITS 0000000000000004 001004 000004 00 A 0 0 1 I find this quite dangerous if an input section has the SHF_WRITE flag. I do not see in what circumstances a user may want this behavior. This just seems very dangerous to use in general. What went lucky is that https://sourceware.org/binutils/docs/ld/Output-Section-Type.html does not have the feature listed yet, so hopefully very few people will be lured to use this.