Harry Wang
|
Re: QNX 6.5 compile with -fstack-protector-all
|
Harry Wang
07/12/2012 11:49 AM
post94224
|
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
|
|
|