Skip to content

Commit 1e1544a

Browse files
authored
Merge pull request #293 from ovpanait/master
[v2] tests: add testcase for alignment issues with contiguous note sections
2 parents 9592fdf + d2bb23b commit 1e1544a

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ AM_INIT_AUTOMAKE([1.11.1 -Wall -Werror dist-bzip2 foreign color-tests parallel-t
66

77
AM_PROG_CC_C_O
88
AC_PROG_CXX
9+
AM_PROG_AS
910

1011
DEFAULT_PAGESIZE=auto
1112
AC_ARG_WITH([page-size],

tests/Makefile.am

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
LIBS =
22

3-
check_PROGRAMS = simple main main-scoped big-dynstr no-rpath
3+
check_PROGRAMS = simple main main-scoped big-dynstr no-rpath contiguous_note_sections
44

55
no_rpath_arch_TESTS = \
66
no-rpath-amd64.sh \
@@ -27,7 +27,8 @@ src_TESTS = \
2727
output-flag.sh \
2828
no-rpath-pie-powerpc.sh \
2929
build-id.sh \
30-
invalid-elf.sh
30+
invalid-elf.sh \
31+
contiguous_note_sections.sh
3132

3233
build_TESTS = \
3334
$(no_rpath_arch_TESTS)
@@ -106,3 +107,7 @@ libsimple_so_LDFLAGS = $(LDFLAGS_sharedlib)
106107
no_rpath_SOURCES = no-rpath.c
107108
# no -fpic for no-rpath.o
108109
no_rpath_CFLAGS =
110+
111+
contiguous_note_sections_SOURCES = contiguous_note_sections.s contiguous_note_sections.ld
112+
contiguous_note_sections_LDFLAGS = -nostdlib -T contiguous_note_sections.ld
113+
contiguous_note_sections_CFLAGS = -pie

tests/contiguous_note_sections.ld

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
PHDRS
2+
{
3+
headers PT_PHDR PHDRS ;
4+
notes PT_NOTE;
5+
text PT_LOAD FILEHDR PHDRS ;
6+
data PT_LOAD ;
7+
interp PT_INTERP ;
8+
dynamic PT_DYNAMIC ;
9+
}
10+
11+
SECTIONS
12+
{
13+
. = SIZEOF_HEADERS;
14+
. = ALIGN(4);
15+
16+
.note.my-section0 : { *(.note.my-section0) } :notes :text
17+
.note.my-section1 : { *(.note.my-section1) } :notes :text
18+
19+
.interp : { *(.interp) } :text :interp
20+
.text : { *(.text) } :text
21+
.rodata : { *(.rodata) } /* defaults to :text */
22+
23+
.data : { *(.data) } :data
24+
}

tests/contiguous_note_sections.s

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Testcase for error:
3+
* patchelf: cannot normalize PT_NOTE segment: non-contiguous SHT_NOTE sections
4+
*/
5+
.section ".note.my-section0", "a", @note
6+
.align 4
7+
.long 1f - 0f /* name length (not including padding) */
8+
.long 3f - 2f /* desc length (not including padding) */
9+
.long 1 /* type = NT_VERSION */
10+
0: .asciz "my-version-12345" /* name */
11+
1: .align 4
12+
2: .long 1 /* desc - toolchain version number, 32-bit LE */
13+
3: .align 4
14+
15+
.section ".note.my-section1", "a", @note
16+
.align 8
17+
.long 1f - 0f /* name length (not including padding) */
18+
.long 3f - 2f /* desc length (not including padding) */
19+
.long 1 /* type = NT_VERSION */
20+
0: .asciz "my-version-1" /* name */
21+
1: .align 4
22+
2: .long 1 /* desc - toolchain version number, 32-bit LE */
23+
3: .align 4

tests/contiguous_note_sections.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#! /bin/sh -e
2+
3+
# Running --set-interpreter on this binary should not produce the following
4+
# error:
5+
# patchelf: cannot normalize PT_NOTE segment: non-contiguous SHT_NOTE sections
6+
../src/patchelf --set-interpreter ld-linux-x86-64.so.2 contiguous_note_sections

0 commit comments

Comments
 (0)