Skip to content

Commit a4e2588

Browse files
committed
Actually test linker script processing
The goto-cc personality does not invoke linker script processing, hence the tests located in the ansi-c folder were a no-op. Moving them to the goto-gcc folder showed that they wouldn't work as is, which is also fixed now: 1) Add -static so as not to generate dynamic linking headers, which those linker scripts leave no room for. 2) Actually detect failure of linker script parsing by enabling warnings and testing for them. 3) Make sure ls_parse.py is available on the PATH. 4) Linker scripts aren't supported by Apple's linker.
1 parent 087296a commit a4e2588

File tree

13 files changed

+35
-10
lines changed

13 files changed

+35
-10
lines changed

regression/goto-gcc/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/archives/libour_archive.a
1515
add_custom_target(libour_archive.a ALL
1616
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/archives/libour_archive.a"
1717
)
18+
19+
if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
20+
set_property(
21+
TEST "goto-gcc-CORE"
22+
PROPERTY ENVIRONMENT
23+
"PATH=$ENV{PATH}:$<TARGET_FILE_DIR:goto-cc>"
24+
)
25+
endif()

regression/goto-gcc/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ tests.log: ../test.pl
1010

1111
else
1212
test: ../../src/goto-cc/goto-gcc
13-
@../test.pl -e -p -c ../../../src/goto-cc/goto-gcc
13+
@PATH=../../../scripts:$$PATH ../test.pl -e -p -c ../../../src/goto-cc/goto-gcc
1414

1515
tests.log: ../test.pl ../../src/goto-cc/goto-gcc
16-
@../test.pl -e -p -c ../../../src/goto-cc/goto-gcc
16+
@PATH=../../../scripts:$$PATH ../test.pl -e -p -c ../../../src/goto-cc/goto-gcc
1717

1818
../../src/goto-cc/goto-gcc: ../../src/goto-cc/goto-cc
1919
@ln -sf goto-cc ../../src/goto-cc/goto-gcc

regression/ansi-c/linker_script_start+end/main.c renamed to regression/goto-gcc/linker_script_start+end/main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ extern char src_start[];
22
extern char src_end[];
33
extern char dst_start[];
44

5-
void *memcpy(void *dest, void *src, unsigned n){
5+
void *memcpy(void *dest, void *src, unsigned n)
6+
{
67
return (void *)0;
78
}
89

9-
int main(){
10+
int main()
11+
{
1012
memcpy(dst_start, src_start, (unsigned)src_end - (unsigned)src_start);
1113
return 0;
1214
}

regression/ansi-c/linker_script_start+end/test.desc renamed to regression/goto-gcc/linker_script_start+end/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
CORE
22
main.c
3-
-o out.gb -T script.ld -nostdlib
3+
-o out.gb -T script.ld -nostdlib -static -Wall
44
^EXIT=0$
55
^SIGNAL=0$
66
--
7+
Problem parsing linker script
78
^warning: ignoring
89
^CONVERSION ERROR$
910
--

regression/ansi-c/linker_script_start+size/main.c renamed to regression/goto-gcc/linker_script_start+size/main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ extern char src_start[];
22
extern char src_size[];
33
extern char dst_start[];
44

5-
void *memcpy(void *dest, void *src, unsigned n){
5+
void *memcpy(void *dest, void *src, unsigned n)
6+
{
67
return (void *)0;
78
}
89

9-
int main(){
10+
int main()
11+
{
1012
memcpy(dst_start, src_start, (unsigned)src_size);
1113
return 0;
1214
}

regression/ansi-c/linker_script_start+size/test.desc renamed to regression/goto-gcc/linker_script_start+size/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
CORE
22
main.c
3-
-o out.gb -T script.ld -nostdlib
3+
-o out.gb -T script.ld -nostdlib -static -Wall
44
^EXIT=0$
55
^SIGNAL=0$
66
--
7+
Problem parsing linker script
78
^warning: ignoring
89
^CONVERSION ERROR$
910
--
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extern char sym[];
22

3-
int main(){
3+
int main()
4+
{
45
int foo = (int)sym;
56
return 0;
67
}

regression/ansi-c/linker_script_symbol-only/test.desc renamed to regression/goto-gcc/linker_script_symbol-only/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
CORE
22
main.c
3-
-o out.gb -T script.ld -nostdlib
3+
-o out.gb -T script.ld -nostdlib -static -Wall
44
^EXIT=0$
55
^SIGNAL=0$
66
--
7+
Problem parsing linker script
78
^warning: ignoring
89
^CONVERSION ERROR$
910
--

src/goto-cc/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ else()
4141
COMMAND "${CMAKE_COMMAND}" -E create_symlink
4242
goto-cc $<TARGET_FILE_DIR:goto-cc>/goto-ld
4343
BYPRODUCTS ${CMAKE_BINARY_DIR}/bin/goto-ld)
44+
add_custom_command(TARGET goto-cc
45+
POST_BUILD
46+
COMMAND "${CMAKE_COMMAND}" -E copy
47+
${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/ls_parse.py
48+
$<TARGET_FILE_DIR:goto-cc>/ls_parse.py
49+
BYPRODUCTS ${CMAKE_BINARY_DIR}/bin/ls_parse.py)
4450

4551
install(
4652
FILES
4753
${CMAKE_BINARY_DIR}/bin/goto-ld
4854
${CMAKE_BINARY_DIR}/bin/goto-gcc
55+
${CMAKE_BINARY_DIR}/bin/ls_parse.py
4956
DESTINATION
5057
${CMAKE_INSTALL_BINDIR})
5158
endif()

src/goto-cc/gcc_mode.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ int gcc_modet::gcc_hybrid_binary(compilet &compiler)
958958

959959
int result=run_gcc(compiler);
960960

961+
#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
961962
if(result==0 &&
962963
cmdline.isset('T') &&
963964
goto_binaries.size()==1 &&
@@ -970,6 +971,7 @@ int gcc_modet::gcc_hybrid_binary(compilet &compiler)
970971
gcc_message_handler);
971972
result=ls_merge.add_linker_script_definitions();
972973
}
974+
#endif
973975

974976
std::string native_tool;
975977

0 commit comments

Comments
 (0)