sonic icon indicating copy to clipboard operation
sonic copied to clipboard

Compile error on centos system

Open mellonyou opened this issue 3 years ago • 18 comments

Does anyone develop native code on Centos?

My ENV: Intel Xeon, Centos 8, Python 3.9.0, clang version 13.0.0, get some compile error with the latest code: (py39_env) [eric@icx250 sonic]$ make mkdir -p internal/native/avx/ echo '// Code generated by Makefile, DO NOT EDIT.' > internal/native/avx/native_amd64.go echo >> internal/native/avx/native_amd64.go sed -e 's/{{PACKAGE}}/avx/g' internal/native/native_amd64.tmpl >> internal/native/avx/native_amd64.go mkdir -p output/avx clang -mno-red-zone -fno-asynchronous-unwind-tables -fno-builtin -fno-exceptions -fno-rtti -fno-stack-protector -nostdlib -O3 -Wall -Werror -Wno-misleading-indentation -Wno-incompatible-pointer-types -msse -mno-sse4 -mavx -mno-avx2 -DUSE_AVX=1 -DUSE_AVX2=0 -S -o output/avx/native.s native/native.c python3 tools/asm2asm/asm2asm.py internal/native/avx/native_amd64.s output/avx/native.s Traceback (most recent call last): File "/home/download/sonic_dir/sonic/tools/asm2asm/asm2asm.py", line 2132, in main() File "/home/download/sonic_dir/sonic/tools/asm2asm/asm2asm.py", line 2067, in main asm.parse(src, proto) File "/home/download/sonic_dir/sonic/tools/asm2asm/asm2asm.py", line 1979, in parse self._parse(src) File "/home/download/sonic_dir/sonic/tools/asm2asm/asm2asm.py", line 1857, in _parse raise SyntaxError('invalid assembly command: ' + cmd.cmd) SyntaxError: invalid assembly command: .text make: *** [Makefile:108: internal/native/avx/native_amd64.s] Error 1

Is this a config problem, or the asm2asm.py just only support the assembly code compile from Mac OS?

mellonyou avatar Oct 20 '22 03:10 mellonyou

do you change native C code?

AsterDY avatar Oct 20 '22 12:10 AsterDY

I want to do some work on native code, but I can't compile successful before I do any change.

Just modify the Makefile for some compile errors: (base) [eric@icx250 sonic]$ git diff Makefile diff --git a/Makefile b/Makefile index afe1b30..20192de 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ CC_amd64 := clang ASM2ASM_amd64 := tools/asm2asm/asm2asm.py

CFLAGS := -mno-red-zone -CFLAGS += -arch x86_64 +#CFLAGS += -arch x86_64 CFLAGS += -fno-asynchronous-unwind-tables CFLAGS += -fno-builtin CFLAGS += -fno-exceptions @@ -43,7 +43,7 @@ CFLAGS += -fno-rtti CFLAGS += -fno-stack-protector CFLAGS += -nostdlib CFLAGS += -O3 -CFLAGS += -Wall -Werror +CFLAGS += -Wall -Werror -Wno-misleading-indentation -Wno-incompatible-pointer-types

mellonyou avatar Oct 21 '22 00:10 mellonyou

DONOT change any flags. At present, asm2asm only supports very limited ASM syntax, not including GOT、.text instruction ... etc —— In one word, you can only use it to write simple C functions, without gcc libs

AsterDY avatar Oct 22 '22 08:10 AsterDY

(base) [eric@icx250 sonic]$ make mkdir -p internal/native/avx/ echo '// Code generated by Makefile, DO NOT EDIT.' > internal/native/avx/native_amd64.go echo >> internal/native/avx/native_amd64.go sed -e 's/{{PACKAGE}}/avx/g' internal/native/native_amd64.tmpl >> internal/native/avx/native_amd64.go mkdir -p output/avx clang -mno-red-zone -arch x86_64 -fno-asynchronous-unwind-tables -fno-builtin -fno-exceptions -fno-rtti -fno-stack-protector -nostdlib -O3 -Wall -Werror -msse -mno-sse4 -mavx -mno-avx2 -DUSE_AVX=1 -DUSE_AVX2=0 -S -o output/avx/native.s native/native.c clang-13: error: argument unused during compilation: '-arch x86_64' [-Werror,-Wunused-command-line-argument] make: *** [Makefile:107: internal/native/avx/native_amd64.s] Error 1

Do not change any word, get this error. You do not have a Linux PC, and have a try?

mellonyou avatar Oct 23 '22 02:10 mellonyou

only use it on macOS and clang 12+

AsterDY avatar Oct 28 '22 08:10 AsterDY

Seems that this is because you have changed the makefile: clang-13: error: argument unused during compilation: '-arch x86_64' [-Werror,-Wunused-command-line-argument]

PureWhiteWu avatar Oct 28 '22 08:10 PureWhiteWu

only use it on macOS and clang 12+

As a open source project, you'd better clarify this limitation in the readme. Do you have the plans to support Linux OS recently?

mellonyou avatar Oct 28 '22 08:10 mellonyou

This is only used for our development, not for sonic's users. If you want to use asm2asm to develop your own code, you can submit issues on its repo. If you want develop sonic, you can contact us about your plan and we will see how it works

AsterDY avatar Oct 28 '22 09:10 AsterDY

I want to modify the native code with AVX512 and check the performance.

mellonyou avatar Oct 28 '22 10:10 mellonyou

Actually our team has tried this and it decreased the speed due to the CPU underclocking effects introduced by AVX512. You can just try it in C-code benchmark (like Google Test, etc.)

AsterDY avatar Oct 31 '22 04:10 AsterDY

Which CPU platform did you test on?

mellonyou avatar Oct 31 '22 05:10 mellonyou

As I know, on the latest Intel platform, Icelake or SPR, the problem of underclocking has been solved. Could you upload the AVX512 code as a branch, I can do some tests on these platform to evaluate this problem.

mellonyou avatar Nov 01 '22 07:11 mellonyou

cc @PureWhiteWu @liuq19 @chenzhuoyu , any code left?

AsterDY avatar Nov 02 '22 12:11 AsterDY

only use it on macOS and clang 12+

As a open source project, you'd better clarify this limitation in the readme. Do you have the plans to support Linux OS recently?

checkout this repo should be compile with clang on linux(arch).But asm2asm need further work

Max-Cheng avatar Nov 06 '22 15:11 Max-Cheng

only use it on macOS and clang 12+

As a open source project, you'd better clarify this limitation in the readme. Do you have the plans to support Linux OS recently?

checkout this repo should be compile with clang on linux(arch).But asm2asm need further work

yeah, asm2asm does not works in Linux because of different asm syntax.

liuq19 avatar Nov 09 '22 02:11 liuq19

only use it on macOS and clang 12+

As a open source project, you'd better clarify this limitation in the readme. Do you have the plans to support Linux OS recently?

checkout this repo should be compile with clang on linux(arch).But asm2asm need further work

yeah, asm2asm does not works in Linux because of different asm syntax.

yep, I believe if we want sonic running on ARM we should spill the work to two-step.

  1. adaptation Sonic native code from Apple Clang to LLVM Clang(now we can compile with LLVM clang, But asm2asm needs further work)
  2. adaptations native code from AVX to NEON(adaptations ARM instruction set) All work needs to contribute asm2asm project, I'm working learn ATT assembly to plan9, but only a few documents of plan9 can be found. it maybe takes looong time.

Max-Cheng avatar Nov 09 '22 03:11 Max-Cheng

only use it on macOS and clang 12+

As a open source project, you'd better clarify this limitation in the readme. Do you have the plans to support Linux OS recently?

checkout this repo should be compile with clang on linux(arch).But asm2asm need further work

yeah, asm2asm does not works in Linux because of different asm syntax.

Any plan to support Linux?

mellonyou avatar Nov 11 '22 02:11 mellonyou

Perhaps using -ffreestanding and small reimplementation of STDC like eg. string.h would not work on freestanding?

Example
> clang -mno-red-zone -target x86_64-apple-macos11 -fno-asynchronous-unwind-tables -fno-builtin -fno-exceptions -fno-rtti -fno-stack-protector -nostdlib -O3 -Wall -Werror -msse -mno-sse4-mavx -mpclmul -mno-avx2 -DUSE_AVX=1 -DUSE_AVX2=0 -S -ffreestanding -o out_avx.s a.c
> cat out_avx.s
	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 11, 0
	.globl	_go_reflect_tree                ## -- Begin function go_reflect_tree
	.p2align	4, 0x90
_go_reflect_tree:                       ## @go_reflect_tree
## %bb.0:
	pushq	%rbp
	movq	%rsp, %rbp
	xorl	%eax, %eax
	cmpq	$1, %rdi
	sbbl	%eax, %eax
	orl	$65535, %eax                    ## imm = 0xFFFF
	popq	%rbp
	retq
                                        ## -- End function
.subsections_via_symbols
> cat a.c
#include <stdint.h>
#include <immintrin.h>
//#include <string.h>

int go_reflect_tree(void* ptr)
{
	register int a = 0;
	if (ptr == 0) return -1;
	if ((uintptr_t)ptr & 0xff) a = 0xff;
	a |= 0xffff;
	return a;
}

ii64 avatar Feb 24 '23 08:02 ii64