Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - QNX 6.5 compile with -fstack-protector-all: (14 Items)
   
QNX 6.5 compile with -fstack-protector-all  
Hi,

I was trying to compile with -fstack-protector-all under QNX 6.5 and I can't. It works on linux, though.

When I compile it is okay, it is like this:

ntox86-gcc-4.4.2 -DX25_RECEIVE_SIZE=256 -D_XOPEN_SOURCE=600 -fPIC -pedantic -Wall -std=c99 -MMD -MP -fstack-protector-
all  -I./qnx-libs -c conn.c -o conn.o
ntox86-gcc-4.4.2 -DX25_RECEIVE_SIZE=256 -D_XOPEN_SOURCE=600 -fPIC -pedantic -Wall -std=c99 -MMD -MP -fstack-protector-
all  -I./qnx-libs -c sockutil.c -o sockutil.o
ntox86-gcc-4.4.2 -DX25_RECEIVE_SIZE=256 -D_XOPEN_SOURCE=600 -fPIC -pedantic -Wall -std=c99 -MMD -MP -fstack-protector-
all  -I./qnx-libs -c timeout.c -o timeout.o
ntox86-gcc-4.4.2 -DX25_RECEIVE_SIZE=256 -D_XOPEN_SOURCE=600 -fPIC -pedantic -Wall -std=c99 -MMD -MP -fstack-protector-
all  -I./qnx-libs -c init_params.c -o init_params.o
ntox86-gcc-4.4.2 -DX25_RECEIVE_SIZE=256 -D_XOPEN_SOURCE=600 -fPIC -pedantic -Wall -std=c99 -MMD -MP -fstack-protector-
all  -I./qnx-libs -c addr_tcp.c -o addr_tcp.o
ntox86-gcc-4.4.2 -DX25_RECEIVE_SIZE=256 -D_XOPEN_SOURCE=600 -fPIC -pedantic -Wall -std=c99 -MMD -MP -fstack-protector-
all  -I./qnx-libs -c lapi_tcp.c -o lapi_tcp.o


But when I link, I get:

ntox86-gcc-4.4.2  -lsocket -lc -shared addr.o pres.o elcom.o bcd.o conn.o sockutil.o timeout.o init_params.o addr_tcp.o 
lapi_tcp.o ./qnx-libs/libev.a  -o libiel-tcp.so
addr.o: In function `iel_addr_suffix':
addr.c:(.text+0x6c): undefined reference to `__stack_chk_fail_local'
addr.o: In function `iel_get_lladdr':
addr.c:(.text+0xf1): undefined reference to `__stack_chk_fail_local'
pres.o: In function `translate_timeout':
pres.c:(.text+0x47): undefined reference to `__stack_chk_fail_local'
pres.o: In function `get_addr_size':
pres.c:(.text+0x117): undefined reference to `__stack_chk_fail_local'
pres.o: In function `copy_addr':
pres.c:(.text+0x1d0): undefined reference to `__stack_chk_fail_local'
pres.o:pres.c:(.text+0x278): more undefined references to `__stack_chk_fail_local' follow
/opt/qnx650/host/linux/x86/usr/bin/ntox86-ld: libiel-tcp.so: hidden symbol `__stack_chk_fail_local' isn't defined
/opt/qnx650/host/linux/x86/usr/bin/ntox86-ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make: *** [libiel-tcp.so] Error 1


Does anyone knows what could be the cause ?



Thanks a lot!

Rodrigo
Re: QNX 6.5 compile with -fstack-protector-all  
I encountered the same thing with BBNDK10.0.6 for x86, arm has no such a  problem though.
Re: QNX 6.5 compile with -fstack-protector-all  
On 12-07-09 05:52 PM, Harry Wang wrote:
> I encountered the same thing with BBNDK10.0.6 for x86, arm has no such a  problem though.

Are you sure you're linking against the 10.0.6 x86 libc and not the 
6.5.0 libc?

Regards,

Ryan Mansfield


Re: QNX 6.5 compile with -fstack-protector-all  
Yes, otherwise armv7 compiler won't work, right?

QNX_TARGET=C:/bbndk/target_10_0_6_324/qnx6
QNX_HOST=C:/bbndk/host_10_0_6_1/win32/x86
MAKEFLAGS=-IC:/bbndk/target_10_0_6_324/qnx6/usr/include
Re: QNX 6.5 compile with -fstack-protector-all  
On 12-07-10 10:18 AM, Harry Wang wrote:
> Yes, otherwise armv7 compiler won't work, right?

No, what does the x86 libc have to do with the arm compiler?

Dumping the 10.0.6 x86 libc, it's ssp support is there in..

$ ntox86-objdump -T lib/libc.so.3 | grep stack_chk
00089654 g    DO .bss	00000004 __stack_chk_guard
00072050 g    DF .text	0000001d __stack_chk_fail

Do -Wl,-t when you're linking and find out which libc you're linking 
against.

Regards,

Ryan Mansfield

Re: QNX 6.5 compile with -fstack-protector-all  
armv7 and x86 compiler and libs are under the same QNX_HOST and QNX_TARGET. If I setup wrongly, armv7 libraries will 
also be 6.5 ones, it won't support stack-protector-strong.

Anyway, here is the -Wl, -t output:

-lc (../../../bbndk/target_10_0_6_324/qnx6/x86/lib/libc.so)
-lm (../../../bbndk/target_10_0_6_324/qnx6/x86/lib/libm.so)

and I still get many:

 undefined reference to `__stack_chk_fail_local'

Re: QNX 6.5 compile with -fstack-protector-all  
And objdump does show:

$ ntox86-objdump -T libc.so.3 |grep stack_chk
00089654 g    DO .bss   00000004 __stack_chk_guard
00072050 g    DF .text  0000001d __stack_chk_fail

$ ntox86-objdump -T libc.so |grep stack_chk
00089654 g    DO .bss   00000004 __stack_chk_guard
00072050 g    DF .text  0000001d __stack_chk_fail
Re: QNX 6.5 compile with -fstack-protector-all  
On 12-07-10 11:53 AM, Harry Wang wrote:
  > Anyway, here is the -Wl, -t output:
>
> -lc (../../../bbndk/target_10_0_6_324/qnx6/x86/lib/libc.so)
> -lm (../../../bbndk/target_10_0_6_324/qnx6/x86/lib/libm.so)


> and I still get many:
>
>   undefined reference to `__stack_chk_fail_local'

__stack_chk_fail_local is hidden in the shared object, and they're only 
in the libcS.a/libc.a. And they're both there...

$ ntox86-nm  x86/lib/libcS.a | grep "T __stack_chk_fail_local"
00000000 T __stack_chk_fail_local
$ ntox86-nm  x86/lib/libc.a | grep "T __stack_chk_fail_local"
00000000 T __stack_chk_fail_local

Regards,

Ryan Mansfield


Re: QNX 6.5 compile with -fstack-protector-all  
Yeah, I can see the symbols. But I still get the link problem.
Re: QNX 6.5 compile with -fstack-protector-all  
On 12-07-10 02:53 PM, Harry Wang wrote:
> Yeah, I can see the symbols. But I still get the link problem.

Hmm, it works for me, and we're also building 10.0.6 with 
-fstack-protector and we're not having any problems.

Are you using the qcc driver? Or the gcc driver? Can you email me an 
test case?

Regards,

Ryan Mansfield
Re: QNX 6.5 compile with -fstack-protector-all  
I am using pure make file under command line. This is Windows version of NDK. I am using ntox86-gcc for compile and link
. Are you also using Windows's NDK?

I will try linux version of the toolchain in a few days.

The project I am building  is pretty big, I'll see if I can make a simpler one and reproduce the problem. 

Thank you very much  for your help. 
Re: QNX 6.5 compile with -fstack-protector-all  
OK, I wrote a simplest sample for this. This problem happens only for linking a so file, no problem for exe file.

I created 5 files, sample1.c, sample2.c, main.c, sample.h and makefile.

You can put these files under one dir and type make under the NDK10.0.6.324 environment. It will build both sample and 
sample.so.0.0. You will see sample created but sample.so.0.0 failed with those undefined reference to `
__stack_chk_fail_local' errors.

And If you comment out CFLAGS += -fstack-protector-all line in the makefile, both sample and sample.so.0.0 will be built
.

Please note that in makefile, there is a hard coded path for libc.so. 

Following are the file contents:

sample1.c
---------------------------------------
#include <stdio.h>

int sample1()
{
  printf("sample1\n");
  return 0;
}

sample2.c
---------------------------------------
#include <stdio.h>

int sample2()
{
  printf("sample2\n");
  return 0;
}


main.c
---------------------------------------
#include "sample.h"

int main(void)
{
  sample1();
  sample2();

  return 0;
}


sample.h
---------------------------------------
extern int sample1(void);
extern int sample2(void);


makefile
---------------------------------------
#
# GNU Makefile
# Sample Applications
#


default: all

CC := ntox86-gcc
CFLAGS += -lang-c -fPIC -DPIC -fsigned-char
CFLAGS += -fstack-protector-all
CFLAGS += -Wformat=2

LD := $(CC)
LDFLAGS += -L$(LIBDIR)
LDFLAGS += -Wl,-z,relro,-z,now
LDFLAGS += -Lc:/bbndk/target_10_0_6_324/qnx6/x86/lib
LDSFLAGS += -shared -nostdlib -nostartfiles 
USEDLIBS += -lc

SRCS := sample1.c sample2.c 

OBJS := $(patsubst %.c,%.o,$(SRCS))

SO := sample.so.0.0 

EXE := sample
#
# targets
#
all: $(EXE) $(SO)

# Compilation command
%.o: %.c
	$(CC) -o $@ -c $(CFLAGS) $<

# Linking command
$(EXE): $(OBJS) main.o
	$(CC) -o $@ $(LDFLAGS) $^ $(USEDLIBS)

%.so.0.0: $(OBJS)
	$(CC) -o $@ $(LDFLAGS) $(LDSFLAGS) $^ $(USEDLIBS) -Wl,-soname,$(notdir $@).0 

clean:
	-rm -f $(EXE) *.o
Re: QNX 6.5 compile with -fstack-protector-all  
As I've mentioned the __stack_chk_fail_local is only available in the libc archive. Normally this is brought in 
implicitly by the driver but you're specifying -nostdlib and only linking against the libc.so..

Regards,

Ryan Mansfield
Re: QNX 6.5 compile with -fstack-protector-all  
I know noramally I don't need specify -lc and the path. I added it just because I am having the link problem.

Anyway, now I know the problem is using -nostdlib. Thanks.