Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-05

Executable stack in shared library

13 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Matthias Klumpp

Hi!
I package a Freepascal project for Debian which uses a shared library. If I run the quality analysis on those packages, I get a warning, that the shared library has an executable stack. [1] Why does it have one, if it is not necessary? How can I disable this in FPC?
Thanks and kind regards
Matthias Klumpp

-------------
Linkbox:
[1] http://lintian.debian.org/tags/shlib-with-executable-stack.html

Tomas Hajny
to Matthias Klumpp

On Fri, May 21, 2010 18:50, Matthias Klumpp wrote:

Hi,

Show quoted text 8 lines
I package a Freepascal project for Debian which uses a shared library. If I run the quality analysis on those packages, I get a warning, that the shared library has an executable stack. [1] Why does it have one, if it is not necessary? How can I disable this in FPC? ------------- Linkbox: [1] http://lintian.debian.org/tags/shlib-with-executable-stack.html

Which shared library (out of those listed) is supposed to be used with FPC? As far as I can see, none of these libraries comes from FPC, it's probably just that one of FPC packages uses it - what are we supposed to do with that?

Tomas

Matthias Klumpp
to Tomas Hajny
Which shared library (out of those listed) is supposed to be used with FPC? As far as I can see, none of these libraries comes from FPC, it's probably just that one of FPC packages uses it - what are we supposed to do with that?

The package is not listed there because the package only lists packages in the Debian archive which have this error. My package is not in Debian yet. I linked the page because it gives a detailed description of the warning.

Jonas Maebe
to Matthias Klumpp: Hi! I package a Freepascal project for Debian which uses a shared library. If I run the…
Matthias Klumpp wrote
I package a Freepascal project for Debian which uses a shared library. If I run the quality analysis on those packages, I get a warning, that the shared library has an executable stack.

Which version of FPC are you using? We have been adding the "do not create an executable stack" section to ELF files since FPC 2.2.4 already.

Why does it have one, if it is not necessary?

The default of the GNU binutils is "create an executable stack". The object files have to contain a special section for it to be disabled.

How can I disable this in FPC?

Update your FPC version. There's also a linker parameter that you can use, but that's not the recommended approach.

Jonas

Matthias Klumpp
to Jonas Maebe

Hi!
Thank you for the information! I use FPC 2.4.0 but get this warning... Here's the output of readelf -l on the shared library: ----------------------------
Elf file type is DYN (Shared object file)
Entry point 0xf3db0
There are 4 program headers, starting at offset 64

Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000358c9c 0x0000000000358c9c R E 200000 LOAD 0x0000000000359000 0x0000000000559000 0x0000000000559000 0x00000000000f11b0 0x0000000000108380 RW 200000 DYNAMIC 0x0000000000359028 0x0000000000559028 0x0000000000559028 0x0000000000000210 0x0000000000000210 RW 8
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 RWE 8

Section to Segment mapping:
Segment Sections...
00 .hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .eh_frame
01 .ctors .dtors .jcr .dynamic .got .got.plt .data fpc.resources .bss fpc.reshandles
02 .dynamic
03
---------------------------
It seems like the E flag is set.
I compile the library with this compiler parameters: -MObjFPC -Scgi -O1 -gl -vewnhi -l
-Fu/usr/share/fpcsrc/2.4.0/packages/dbus/src/
-Fu/usr/lib/lazarus/0.9.29/lcl/units/x86_64-linux/ -Fu/usr/lib/lazarus/0.9.29/lcl/units/x86_64-linux/nogui/ -Fu. -vm5024 -fPIC

(I removed some of the -FU includes)

Regards
Matthias

Jonas Maebe wrote
On 21 May 2010, at 18:50, Matthias Klumpp wrote: > I package a Freepascal project for Debian which uses a shared library.

If

Show quoted text 5 lines
> I > run the quality analysis on those packages, I get a warning, that the > shared library has an executable stack. Which version of FPC are you using? We have been adding the "do not

create

Show quoted text 6 lines
an executable stack" section to ELF files since FPC 2.2.4 already. > Why does it have one, if it is > not necessary? The default of the GNU binutils is "create an executable stack". The

object

Show quoted text 5 lines
files have to contain a special section for it to be disabled. > How can I disable this in FPC? Update your FPC version. There's also a linker parameter that you can

use,

Show quoted text 6 lines
but that's not the recommended approach. Jonas_______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Jonas Maebe
to Matthias Klumpp
Matthias Klumpp wrote
Thank you for the information! I use FPC 2.4.0 but get this warning...

Then I don't know what the problem is. I cannot reproduce it.

It seems like the E flag is set.

That suggests that one of the object files used to link this library is missing a ".note.GNU-stack" section for some reason.

Jonas

Matthias Klumpp
to Jonas Maebe
Show quoted text 8 lines
> Thank you for the information! I use FPC 2.4.0 but get this warning... Then I don't know what the problem is. I cannot reproduce it. > It seems like the E flag is set. That suggests that one of the object files used to link this library is missing a ".note.GNU-stack" section for some reason.

How can I detect which one it is? (How can I list the sections of an object file?)
Thanks!

Jonas Maebe
to Matthias Klumpp
Matthias Klumpp wrote
> That suggests that one of the object files used to link this library is > missing a ".note.GNU-stack" section for some reason. How can I detect which one it is? (How can I list the sections of an object file?)

readelf -S

If you compile the library with the -Cn parameter, the linking step will be skipped and the compiler will generate a file called link.res that (a.o.) contains all object files that will be linked into the library.

Jonas

Matthias Klumpp
to Jonas Maebe
Jonas Maebe wrote 11 lines
On 22 May 2010, at 14:00, Matthias Klumpp wrote: >> That suggests that one of the object files used to link this library is >> missing a ".note.GNU-stack" section for some reason. > How can I detect which one it is? (How can I list the sections of an > object > file?) readelf -S If you compile the library with the -Cn parameter, the linking step will

be

skipped and the compiler will generate a file called link.res that (a.o.) contains all object files that will be linked into the library.

I checked the files, all .o files had the section. But there was also an .or file of the new FPC resource system in INPUT() this file had no .note.GNU-stack section.
Is that relevant?

Matthias

Jonas Maebe
to Matthias Klumpp
Matthias Klumpp wrote
I checked the files, all .o files had the section. But there was also an .or file of the new FPC resource system in INPUT() this file had no .note.GNU-stack section. Is that relevant?

Actually, yes. The ELF resource writer should probably add such a section as well.

Jonas

Matthias Klumpp
to Jonas Maebe
Jonas Maebe wrote 9 lines
On 22 May 2010, at 19:25, Matthias Klumpp wrote: > I checked the files, all .o files had the section. But there was also an > .or file of the new FPC resource system in INPUT() this file had no > .note.GNU-stack section. > Is that relevant? Actually, yes. The ELF resource writer should probably add such a section as well.

Should I write a bug report for this?

Jonas Maebe
to Matthias Klumpp
Matthias Klumpp wrote 6 lines
On Sat, 22 May 2010 20:38:59 +0200, Jonas Maebe wrote: > > Actually, yes. The ELF resource writer should probably add such a section > as well. Should I write a bug report for this?

Yes.

Jonas