bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug gas/28262] Add warning when generating code in data section


From: dcmay at copper dot net
Subject: [Bug gas/28262] Add warning when generating code in data section
Date: Tue, 07 Sep 2021 16:18:43 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=28262

--- Comment #5 from Dietmar May <dcmay at copper dot net> ---
> Ran in what environment ?

Bare metal aarch64 boot loader - the very first steps in bring up an existing
custom operating system on a new hardware platform.

> So how did the assembled-into-a-data-section code get executed ?

It's a multi-core processor, each core has a distinct _start: memory address.
Therefore, each core has to have its own .text section, except they can't be
called .text, because there are multiple distinct sections.

The assembler code is just a few hundred lines - disables interrupts,
watchdogs, sets up MMU. Then it branches to C/C++ code (ie. _main:), with the
occasional GCC inline assembler block.

> Do you mean the linker script ?  Maybe this is the problem.  Maybe the
> script is putting data input sections into a executable output section
> (or segment).

Well, yes, that's what the linker script does. But, hmm, is that the problem?

Reason that an assembler exists: to convert symbolic mnemonics into hexadecimal
(or binary) machine op codes that a CPU can execute.

Reasons sections exist: to break up code into individual, relocatable blocks of
machine op codes.

Default meaning of sections: data!

Huh?

I've been told that's to prevent people who are writing self-relocating code
from accidentially opening security holes.

But why turn code quietly into data, by default?

If someone wants to write self-relocating code, they can specify the section
type as data.

If it's really that dangerous to have code default to being code, then remove
the default!

Though that would undoubtedly break existing codebases. So if that's not
desirable, then at least issue a warning.

> Which would require that the assembler looks ahead through the input source

Or that the assembler sets a flag when is sees and assembles code within a
defaulted section, and when it reaches the end of the section, it emits a
warning if the flag is set.

> a general principle that ... you do need to know what you are doing

I've been writing C++ code since shortly after Stroustrup released his first
edition of The C++ Programming Language; and I've done x86 and embedded
assembler, as well as bare metal machine language. I'm not a novice developer.
However, I am far more comfortable with g++ than with gas; this is my first
dive into using gas; and I'll be the first to admit I have a lot to learn.

I was helping to port a bootloader from a commercial compiler/assembler suite
to g++/gas, and the syntax is more than a bit different.

So I searched, and found lots of examples of .text, .bss, .data sections. None
of them were qualified with optional flags - because they're well known section
names.

I found no examples of more complex scenarios, like .text1, .text2, etc. And in
adapting .text examples to .text1, .text2, gas happily assembled and ld happily
linked the code, without any warnings or errors. And the processor happily ran
the code, and gdb happily debugged the code. And so I was happy :-) ... until
binutils 2.36.1 broke debugging.

Perhaps an example of something more than "Hello World" would be really useful.

Most of all, I think that .section should not have any default, except perhaps
for well known names like .text; and then the programmer is forced to make a
decision about what the section should be.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]