mirror of
https://github.com/gatieme/LDD-LinuxDeviceDrivers.git
synced 2026-09-26 07:24:00 +08:00
gcc优化和如何使用-O2编译内核...
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// http://blog.csdn.net/liyuanbhu/article/details/42470577
|
||||
/*
|
||||
mm/memory.o: In function `insert_pfn':
|
||||
/home/gatieme/Work/Kernel/linux/linux/mm/memory.c:1813: undefined reference to `pte_mkdevmap'
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//#define CONFIG_TARGET_X86_64
|
||||
|
||||
#ifdef CONFIG_TARGET_X86_64
|
||||
static void A( )
|
||||
{
|
||||
printf("A\n");
|
||||
}
|
||||
#else
|
||||
void A( ) __attribute__ ((weak));;
|
||||
#endif
|
||||
|
||||
static void B( )
|
||||
{
|
||||
printf("B\n");
|
||||
}
|
||||
|
||||
|
||||
static int xx( )
|
||||
{
|
||||
#ifdef CONFIG_TARGET_X86_64
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
if (xx( )) /* define CONFIG_TARGET_X86_64 */
|
||||
A( );
|
||||
else
|
||||
B( );
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*************************************************************************
|
||||
> File Name: 1.c
|
||||
> Author: GatieMe
|
||||
> Mail: gatieme@163.com
|
||||
> Created Time: Sun 26 Nov 2017 11:47:59 AM CST
|
||||
************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
static void A( );
|
||||
|
||||
|
||||
#ifdef CONFIG_TEST_MACRO
|
||||
static void A( )
|
||||
{
|
||||
printf("A\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
static void xx( )
|
||||
{
|
||||
A( );
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
xx( );
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// http://blog.csdn.net/liyuanbhu/article/details/42470577
|
||||
/*
|
||||
mm/memory.o: In function `insert_pfn':
|
||||
/home/gatieme/Work/Kernel/linux/linux/mm/memory.c:1813: undefined reference to `pte_mkdevmap'
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//#define CONFIG_TARGET_X86_64
|
||||
|
||||
#ifdef CONFIG_TARGET_X86_64
|
||||
static int xx( )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void A( )
|
||||
{
|
||||
printf("A\n");
|
||||
}
|
||||
#else
|
||||
static int xx( )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//void A( ) __attribute__ ((weak));;
|
||||
void A( );// __attribute__ ((weak));;
|
||||
#endif
|
||||
|
||||
static void B( )
|
||||
{
|
||||
printf("B\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
if (xx( )) /* define CONFIG_TARGET_X86_64 */
|
||||
A( );
|
||||
else
|
||||
B( );
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// http://blog.csdn.net/liyuanbhu/article/details/42470577
|
||||
/*
|
||||
mm/memory.o: In function `insert_pfn':
|
||||
/home/gatieme/Work/Kernel/linux/linux/mm/memory.c:1813: undefined reference to `pte_mkdevmap'
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//#define CONFIG_TARGET_X86_64
|
||||
|
||||
#ifdef CONFIG_TARGET_X86_64
|
||||
static int xx( )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void A( )
|
||||
{
|
||||
printf("A\n");
|
||||
}
|
||||
#else
|
||||
static int xx( )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//void A( ) __attribute__ ((weak));;
|
||||
void A( );// __attribute__ ((weak));;
|
||||
#endif
|
||||
|
||||
static void B( )
|
||||
{
|
||||
printf("B\n");
|
||||
}
|
||||
|
||||
static void AA( )
|
||||
{
|
||||
A( );
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
if (xx( )) /* define CONFIG_TARGET_X86_64 */
|
||||
A( );
|
||||
else
|
||||
B( );
|
||||
AA( );
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#
|
||||
#http://blog.sina.com.cn/s/blog_694f2ae70101amh6.html
|
||||
#
|
||||
target=test
|
||||
|
||||
CURRENT_BIN_DIR=ptrace_bug
|
||||
INSTALL_ROOT_DIR=~/Work/Kernel/runninglinuxkernel/filesystem
|
||||
INSTALL_HOME_DIR=home/chengjian
|
||||
|
||||
ifeq ($(ARCH), arm64)
|
||||
CROSS_COMPILE=/opt/arm/toolschain/linaro/gcc-linaro-7.1.1-2017.08-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
|
||||
ARCH_FILE_DIR=_install_arm64
|
||||
else ifeq ($(ARCH), arm32)
|
||||
CROSS_COMPILE=arm-linux-gnueabi-
|
||||
ARCH_FILE_DIR=_install_arm32
|
||||
else # ifeq ($(ARCH), x86_64)
|
||||
ARCH_FILE_DIR=_install_x86
|
||||
endif
|
||||
|
||||
INSTALL_BIN_DIR=$(INSTALL_ROOT_DIR)/$(ARCH_FILE_DIR)/$(INSTALL_HOME_DIR)/ #$(CURRENT_BIN_DIR)
|
||||
|
||||
CFLAGS+= -finline-small-functions \
|
||||
-findirect-inlining \
|
||||
-fpartial-inlining \
|
||||
-finline-functions \
|
||||
-finline-functions-called-once
|
||||
|
||||
CC=${CROSS_COMPILE}gcc
|
||||
AS=${CROSS_COMPILE}as
|
||||
LD=${CROSS_COMPILE}ld
|
||||
LDFLAGS+=-static
|
||||
|
||||
|
||||
all : $(target)
|
||||
|
||||
test:test.c
|
||||
$(CC) $^ -o $@ $(LDFLAGS) $(CFLAGS)
|
||||
@echo "ptrace singlestep..."
|
||||
|
||||
%.o : %.c
|
||||
$(CC) -c $^ -o $@ $(CFLAGS) $(DEFINES)
|
||||
|
||||
%.o : %.cpp
|
||||
$(CXX) -c $^ -o $@ $(CFLAGS) $(DEFINES)
|
||||
|
||||
clean :
|
||||
rm -rf *.o
|
||||
rm -rf $(target)
|
||||
|
||||
install :
|
||||
mkdir -p $(CURRENT_BIN_DIR)
|
||||
cp $(target) $(CURRENT_BIN_DIR)
|
||||
#echo $(INSTALL_BIN_DIR)
|
||||
cp -rf $(CURRENT_BIN_DIR) $(INSTALL_BIN_DIR)
|
||||
@@ -0,0 +1,45 @@
|
||||
// http://blog.csdn.net/liyuanbhu/article/details/42470577
|
||||
/*
|
||||
mm/memory.o: In function `insert_pfn':
|
||||
/home/gatieme/Work/Kernel/linux/linux/mm/memory.c:1813: undefined reference to `pte_mkdevmap'
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//#define CONFIG_TARGET_X86_64
|
||||
|
||||
#ifdef CONFIG_TARGET_X86_64
|
||||
static void A( )
|
||||
{
|
||||
printf("A\n");
|
||||
}
|
||||
#else
|
||||
static void A( )
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
static void B( )
|
||||
{
|
||||
printf("B\n");
|
||||
}
|
||||
|
||||
|
||||
inline int xx( )
|
||||
//static inline int xx( ) /* right */
|
||||
//int xx( ) /* right */
|
||||
{
|
||||
#ifdef CONFIG_TARGET_X86_64
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
if (xx( ))
|
||||
A( );
|
||||
else
|
||||
B( );
|
||||
}
|
||||
Reference in New Issue
Block a user