From: Bart Van Assche <bvanassche@acm.org>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Nathan Chancellor <natechancellor@gmail.com>,
ooo@electrozaur.com,
"James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] libosd: Remove ignored __weak attribute
Date: Tue, 02 Oct 2018 10:57:43 -0700 [thread overview]
Message-ID: <1538503063.193396.6.camel@acm.org> (raw)
In-Reply-To: <CAKwvOd=wgxB69dMxzMeH2edCn=TdQGPGkNVW1e=QHPTJtO9ZNw@mail.gmail.com>
On Tue, 2018-10-02 at 10:24 -0700, Nick Desaulniers wrote:
> On Mon, Oct 1, 2018 at 6:16 PM Bart Van Assche <bvanassche@acm.org> wrote:
> > Additionally, zero initializers should be left out to minimize
> > the size of object files.
>
> Sorry, my understanding was that global variables either occupy the
> .bss section or the .data section, depending on whether they were
> zero-initialized vs initialized to non-zero, respectively (where
> non-initialized are treated as zero initialized). Looks like without
> the explicit zero initialization, compilers will put the symbols in a
> "common" section, which `man 1 nm` says is also unitialized data. I
> didn't think .bss sections occupied space in an object file or binary;
> the kernel's loader would set up the mappings at execution? Can you
> clarify?
Explicitly initialized global and static variables end up in the .data
section and need space in that section. That is not the case if the
initializer is left out and these variables end up in the .bss section.
>From https://en.wikipedia.org/wiki/.bss:
"In computer programming, the name .bss or bss is used by many compilers
and linkers for the portion of an object file or executable containing
statically-allocated variables that are not explicitly initialized to any
value. It is often referred to as the "bss section" or "bss segment".
Typically only the length of the bss section, but no data, is stored in
the object file."
This is why checkpatch warns if a global or static variable is initialized
explicitly to zero. From scripts/checkpatch.pl:
our $zero_initializer = qr{(?:(?:0[xX])?0+$Int_type?|NULL|false)\b};
# check for global initialisers.
if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/) {
if (ERROR("GLOBAL_INITIALISERS",
"do not initialise globals to $1\n" . $herecurr) && $fix) {
$fixed[$fixlinenr] =~ s/(^.$Type\s*$Ident(?:\s+$Modifier)*)\s*=\s*$zero_initializer\s*;/$1;/;
}
}
# check for static initialisers.
if ($line =~ /^\+.*\bstatic\s.*=\s*($zero_initializer)\s*;/) {
if (ERROR("INITIALISED_STATIC",
"do not initialise statics to $1\n" . $herecurr) && $fix) {
$fixed[$fixlinenr] =~ s/(\bstatic\s.*?)\s*=\s*$zero_initializer\s*;/$1;/;
}
}
Bart.
next prev parent reply other threads:[~2018-10-02 17:57 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-30 20:54 [PATCH] libosd: Remove ignored __weak attribute Nathan Chancellor
2018-10-01 22:47 ` Nick Desaulniers
2018-10-02 1:16 ` Bart Van Assche
2018-10-02 6:55 ` Nathan Chancellor
2018-10-02 14:56 ` Christoph Hellwig
2018-10-02 16:59 ` Boaz Harrosh
2018-10-02 17:24 ` Nick Desaulniers
2018-10-02 17:57 ` Bart Van Assche [this message]
2018-10-02 22:33 ` Nick Desaulniers
2018-10-02 23:06 ` Bart Van Assche
2018-10-25 21:31 ` Nathan Chancellor
2018-10-25 22:02 ` Nick Desaulniers
2018-10-25 22:55 ` Nathan Chancellor
2018-10-26 17:54 ` Nick Desaulniers
2018-10-26 18:01 ` Bart Van Assche
2018-10-26 18:05 ` Nathan Chancellor
2018-10-26 18:31 ` Nick Desaulniers
2018-10-26 19:22 ` Linus Torvalds
2018-10-26 20:05 ` Nick Desaulniers
2018-10-26 20:42 ` Linus Torvalds
2018-10-26 21:02 ` Nick Desaulniers
2018-10-26 21:00 ` Nick Desaulniers
2018-10-26 21:30 ` Bart Van Assche
2018-10-26 21:36 ` Nick Desaulniers
2018-10-26 21:59 ` Bart Van Assche
2018-10-26 22:07 ` Nick Desaulniers
2018-10-26 22:24 ` Bart Van Assche
2018-10-27 13:28 ` Martin K. Petersen
2018-10-28 15:44 ` Christoph Hellwig
2018-11-01 1:05 ` Boaz Harrosh
2018-10-27 3:35 ` Theodore Y. Ts'o
2018-10-27 6:15 ` Bart Van Assche
2018-10-27 6:25 ` Nathan Chancellor
2018-11-01 1:15 ` Boaz Harrosh
2018-11-01 1:39 ` Boaz Harrosh
2018-11-01 1:44 ` Nathan Chancellor
2019-01-26 6:47 ` [PATCH RESEND] " Nathan Chancellor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1538503063.193396.6.camel@acm.org \
--to=bvanassche@acm.org \
--cc=jejb@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=natechancellor@gmail.com \
--cc=ndesaulniers@google.com \
--cc=ooo@electrozaur.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).