Bug 29498 - Is it expected that eu-strip strips .note.GNU-stack
Summary: Is it expected that eu-strip strips .note.GNU-stack
Status: NEW
Alias: None
Product: elfutils
Classification: Unclassified
Component: tools (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-16 21:23 UTC by Jan Palus
Modified: 2022-10-28 23:06 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2022-08-17 00:00:00
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Palus 2022-08-16 21:23:27 UTC
Accidentally we've started to strip crt*.o files produced by glibc and were surprised by the fact that eu-strip gets rid of .note.GNU-stack section resulting in incorrect linking.

$ gcc -c test.c -o test.o
$ readelf -S test.o|grep GNU-stack
  [ 5] .note.GNU-stack   PROGBITS         0000000000000000  00000074
$ eu-strip test.o
$ readelf -S test.o|grep GNU-stack
(empty)

I see following comment in strip.c:

> - special sections named ".comment" and ".note" are kept

 https://sourceware.org/git/?p=elfutils.git;a=blob;f=src/strip.c;h=452b12796dd3b7ff3a46d13a2bfb9aa0f5c93ac9;hb=HEAD#l1361

The question is whether observed behavior is expected or rather .note.GNU-stack should be kept?
Comment 1 Martin Liska 2022-08-17 07:16:54 UTC
It's definitelly not consistent with strip (from binutils) that keeps the section.
Comment 2 Mark Wielaard 2022-10-27 20:34:05 UTC
Actual SHF_NOTE sections are kept, as are allocated SHF_PROGBITS sections. But this is neither.

How does binutils strip know it should keep this section? Does it just hard-code the name?
Comment 3 Jan Palus 2022-10-28 23:06:04 UTC
If I understand it correctly in binutils primary criteria for removing section is whether it is marked with SEC_DEBUGGING flag:

https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=binutils/objcopy.c;h=d20aaef9f4f2e2a910bd7bf666dab6e3c158fc1b;hb=HEAD#l1366

and the flag for ELF seems to be set here:

https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elf.c;h=81825b748d75f2b68a6cca1c54b126df53c36dc2;hb=HEAD#l1093

	  if (startswith (name, ".debug")
	      || startswith (name, ".gnu.debuglto_.debug_")
	      || startswith (name, ".gnu.linkonce.wi.")
	      || startswith (name, ".zdebug"))
	    flags |= SEC_DEBUGGING | SEC_ELF_OCTETS;
	  else if (startswith (name, GNU_BUILD_ATTRS_SECTION_NAME)
		   || startswith (name, ".note.gnu"))
	    {
	      flags |= SEC_ELF_OCTETS;
	      opb = 1;
	    }
	  else if (startswith (name, ".line")
		   || startswith (name, ".stab")
		   || strcmp (name, ".gdb_index") == 0)
	    flags |= SEC_DEBUGGING;