我做了个编译器把C/C++编译成动态内存安全代码, 让C容易学/用

c
cstack
楼主 (未名空间)


主页:https://www.cee.studio

它的优势: https://www.cee.studio/benefits.html

Online IDE to test out: https://cee.studio

用C做的Discord库, https://github.com/cee-studio/orca

我们现在在探索用纯C和嵌入式脚本engine做bot/webapp后台开发. 希望和需要用C的公司和或个人和作. 我是美国公民也可以接外包项目.

潜水多年,很是受益. 特别是netghost对C和其他语言的深刻见解

m
magagop

這個跟wasm、wasi的區別是什麼呢,謝謝
T
TeacherWei

赞一个!问题:有没有和valgrind比较?你这个和valgrind比有什么优势和劣势呢?
g
guvest
https://www.cee.studio/comparison.html

【 在 TeacherWei(TW) 的大作中提到: 】

: 赞一个!问题:有没有和valgrind比较?你这个和valgrind比有什么优势和劣势呢?

T
TeacherWei

这个要点赞!做的不错!确实花了功夫!
把ARM/MIPS/RISCV都做出来,就更完美了。
c
cstack
https://www.cee.studio/comparison.html

我的可以保证runtime memory safety. All runtime memory errors can be reported. (I submitted a POPL paper with proof. Unfortunately, it was not accepted, one reviewer recommended to submit to PLDI, I didn't bother with it).

【 在 TeacherWei (TW) 的大作中提到: 】
: 赞一个!问题:有没有和valgrind比较?你这个和valgrind比有什么优势和劣势呢?

c
cstack

It generated native code with runtime checking to check all memory errors.
In theory, it can even check type safety.

【 在 magagop (magagop) 的大作中提到: 】
: 這個跟wasm、wasi的區別是什麼呢,謝謝

T
TeacherWei

会不会有false-positive?一般协议栈都会有指针类型cast之类。

【 在 cstack (cstack) 的大作中提到: 】
: https://www.cee.studio/comparison.html
: 我的可以保证runtime memory safety. All runtime memory errors can be
reported
: . (I submitted POPL paper with proof. Unfortunately, it was not accepted, : one reviewer recommended to submitted to PLDI, I didn't bother with it).

c
cstack

我判断是,最大化大的市场不是嵌入系统. 我有可能错得

【 在 TeacherWei (TW) 的大作中提到: 】
: 这个要点赞!做的不错!确实花了功夫!
: 把ARM/MIPS/RISCV都做出来,就更完美了。

c
cstack

没有 false-positive.

【 在 TeacherWei (TW) 的大作中提到: 】
: 会不会有false-positive?一般协议栈都会有指针类型cast之类。
: reported

T
TeacherWei

比如:

struct header {
......
another_struct data[];
}

这个data其实没有占空间。但是可以用

(another_struct *)(pHeader + 1)

引用。

【 在 TeacherWei (TW) 的大作中提到: 】
: 会不会有false-positive?一般协议栈都会有指针类型cast之类。
: reported

c
cstack

A very good example, It will not report this as out-of-bounds access.

【 在 TeacherWei (TW) 的大作中提到: 】
: 比如:
: struct header {
: ......
: another_struct data[];
: }
: 这个data其实没有占空间。但是可以用
: (another_struct *)(pHeader + 1)
: 引用。

T
TeacherWei

我猜你的heap用了非常sparse的虚拟地址,是这样么?

【 在 cstack (cstack) 的大作中提到: 】
: A very good example, It will not report this as out-of-bounds access.

c
cstack

A great question. You have a very deep understanding of the existing
solutions.

没有, 不需要OS support. It can generate code to run on bare metal with
memory safety/type safety.

【 在 TeacherWei (TW) 的大作中提到: 】
: 我猜你的heap用了非常sparse的虚拟地址,是这样么?

T
TeacherWei

我有一个手写的serializer/deserializer库。所有类型都要和uint8_t *互相转换。不理解type safety如何实现?理论上这属于停机问题。

【 在 cstack (cstack) 的大作中提到: 】
: A great question. You have a very deep understanding of the existing
: solutions.
: 没有, 不需要OS support. It can generate code to run on bare metal with
: memory safety/type safety.

c
cstack

Please forgive me for typing in English. Haven't typed Chinese for a very
long time, and my pinyin sucks. It's too slow for me.

Type safety is to strict for some C code. It does not apply to every use
case. But the type of each defined memory cell can be kept at runtime and
used to check its uses. For example, a float value can be assigned to a
union like the following:

union fi {
float f;
int i;
} x;

x.f = 10.0;

If x.i is used later, it can be reported.

It's possible, but I don't see the requirement yet, so I didn't implement it.

It's a runtime detection, so the halting problem does not apply here.

【 在 TeacherWei (TW) 的大作中提到: 】
: 我有一个手写的serializer/deserializer库。所有类型都要和uint8_t *互相转换。不
: 理解type safety如何实现?理论上这属于停机问题。

T
TeacherWei

Excellent!

Although there are cases that break the rule, such as assigning a uint64_t
to a double, it happens very rarely.

You can give programmers finer control with #pragma

Overall, it is good design! Congratulations and best luck!

【 在 cstack (cstack) 的大作中提到: 】
: Please forgive me for typing in English. Haven't typed Chinese for a very : long time, and my pinyin sucks. It's too slow for me.
: Type safety is to strict for some C code. It does not apply to every use
: case. But the type of each defined memory cell can be kept at runtime and
: used to check its uses. For example, a float value can be assigned to a
: union like the following:
: union fi {
: float f;
: int i;
: } x;
: ...................

c
cstack

它能帮助刚学C的掌握指针和C's memory model. 我用CS50的学生做过评估.UCF的学生
也有用.

【 在 magagop (magagop) 的大作中提到: 】
: 這個跟wasm、wasi的區別是什麼呢,謝謝

n
netghost

Very nice, actually I think with this kind of tools and platform, criticism on C's "memory safety" are greatly exaggerated.

Just took a look at your demo, did several not so trivial test seems quite
good to me. Seems you did both runtime and static analysis?

Web editor is quite nice too, although sometimes it doesn't refresh after
source code change.

BTW, what are the main users for this tool so far?

【 在 cstack (cstack) 的大作中提到: 】
: 主页:https://www.cee.studio
: 它的优势: https://www.cee.studio/benefits.html
: Online IDE to test out: https://cee.studio
: 用C做的Discord库, https://github.com/cee-studio/orca
: 我们现在在探索用纯C和嵌入式脚本engine做bot/webapp后台开发. 希望和需要用C的公
: 司和或个人和作. 我是美国公民也可以接外包项目.
: 潜水多年,很是受益. 特别是netghost对C和其他语言的深刻见解

b
bihai

没看到效果啊

char *a="good morning";
printf("I am alive! Beware.%sn", a);
printf("I am alive! Beware.%cn", a[15]);

【 在 cstack (cstack) 的大作中提到: 】
: 主页:https://www.cee.studio
: 它的优势: https://www.cee.studio/benefits.html
: Online IDE to test out: https://cee.studio
: 用C做的Discord库, https://github.com/cee-studio/orca
: 我们现在在探索用纯C和嵌入式脚本engine做bot/webapp后台开发. 希望和需要用C的公
: 司和或个人和作. 我是美国公民也可以接外包项目.
: 潜水多年,很是受益. 特别是netghost对C和其他语言的深刻见解

l
littlebirds3

读取是安全的.

【 在 bihai (学得不好) 的大作中提到: 】
: 没看到效果啊
: char *a="good morning";
: printf("I am alive! Beware.%sn", a);
: printf("I am alive! Beware.%cn", a[15]);

G
GPF

这是真厉害了!
c
cstack


【 在 netghost (Up to Isomorphism) 的大作中提到: 】
: Very nice, actually I think with this kind of tools and platform,
criticism
: on C's "memory safety" are greatly exaggerated.
: Just took a look at your demo, did several not so trivial test seems quite
: good to me. Seems you did both runtime and static analysis?
: Web editor is quite nice too, although sometimes it doesn't refresh after : source code change.
: BTW, what are the main users for this tool so far?

The online IDE is for students to do their C assignments, and the marketing purpose.

The SDK can be used to develop real backend apps. We are using it develop
bots/webapp now. The SDK can build all essential libraries that are needed to build a cloud backend/infra structures.

Here is a partial list of supported packages: https://github.com/cee-studio/packages

We have built 500ish linux packages which are not listed here.

l
littlebirds3

做的真好!
c
cstack


【 在 netghost (Up to Isomorphism) 的大作中提到: 】
: Very nice, actually I think with this kind of tools and platform,
criticism
: on C's "memory safety" are greatly exaggerated.

Yes, C standard does not exclude memory safe implementations. It's just none has done before.

: Just took a look at your demo, did several not so trivial test seems quite
: good to me. Seems you did both runtime and static analysis?

Only runtime checking. static analysis has too much false positives to my
liking.

: Web editor is quite nice too, although sometimes it doesn't refresh after : source code change.
: BTW, what are the main users for this tool so far?

c
chebyshev

有无大点的程序检查之结果展示?
例如:https://www.lua.org/source/5.4/lua.c.html
之类的。
另外网站似乎公司名什么的不全?这样我无法注册。
【 在 cstack (cstack) 的大作中提到: 】
: 主页:https://www.cee.studio
: 它的优势: https://www.cee.studio/benefits.html
: Online IDE to test out: https://cee.studio
: 用C做的Discord库, https://github.com/cee-studio/orca
: 我们现在在探索用纯C和嵌入式脚本engine做bot/webapp后台开发. 希望和需要用C的公
: 司和或个人和作. 我是美国公民也可以接外包项目.
: 潜水多年,很是受益. 特别是netghost对C和其他语言的深刻见解

d
dumbCoder

"Only runtime checking. static analysis has too much false positives to my
liking."

只有 runtime checking 的话, 那内存错误检测(和错误信息)是要程序跑出错了才知道了?
当然, 这样也很厉害了.

【 在 cstack (cstack) 的大作中提到: 】
: criticism
: Yes, C standard does not exclude memory safe implementations. It's just
none
: has done before.
: Only runtime checking. static analysis has too much false positives to my : liking.

c
chebyshev

还一个问题是C的模型可以很不一样。

楼主说,
"
我的可以保证runtime memory safety. All runtime memory errors can be reported. (I submitted a POPL paper with proof. Unfortunately, it was not accepted,
one reviewer recommended to submit to PLDI, I didn't bother with it).
"

楼主如果有论文证明方法,我想看看C的模型之定义。
【 在 dumbCoder (HumbleCoder 不懂就问-_-) 的大作中提到: 】
: "Only runtime checking. static analysis has too much false positives to my: liking."
: 只有 runtime checking 的话, 那内存错误检测(和错误信息)是要程序跑出错了才知道
: 了?
: 当然, 这样也很厉害了.
: none

c
cstack

这个bug就是我使用的时后发现的 https://github.com/risoflora/libsagui/issues/
52

还有一个 libressl's use-after free, 我自己修了没报. https://github.com/cee-studio/packages/commit/
2557ba4bd1a05e2fdf2519c62118c00ea1ac492f#diff-
617be6f15e50bb972bbdd06ff13b40992a4e64a9d5dd2742f06f50d32aa44fcb

【 在 chebyshev (......) 的大作中提到: 】
: 有无大点的程序检查之结果展示?
: 例如:https://www.lua.org/source/5.4/lua.c.html
: 之类的。
: 另外网站似乎公司名什么的不全?这样我无法注册。

d
dumbCoder

对了,请问楼主,这样编译出来执行文件,执行效率有多大影响?
c
cstack

只使用于portable sequential C code. The memory model for portable C code is actually very simple.

【 在 chebyshev (......) 的大作中提到: 】
: 还一个问题是C的模型可以很不一样。
: 楼主说,
: "
: 我的可以保证runtime memory safety. All runtime memory errors can be
reported
: . (I submitted a POPL paper with proof. Unfortunately, it was not accepted,
: one reviewer recommended to submit to PLDI, I didn't bother with it).
: "
: 楼主如果有论文证明方法,我想看看C的模型之定义。

c
chebyshev

如果有论文,应能对推广有正面作用。祝楼主成功。
【 在 cstack (cstack) 的大作中提到: 】
: 只使用于portable sequential C code. The memory model for portable C code is
: actually very simple.
: reported

c
cstack

有很大影响, 但是可支撑快速iterations, 能迅速找到memory bugs. 不一定适合于生产部署.

【 在 dumbCoder (HumbleCoder 不懂就问-_-) 的大作中提到: 】
: 对了,请问楼主,这样编译出来执行文件,执行效率有多大影响?

C
Caravel

去hackernews,reddit相关版面发个文章把,比这里影响力大。

【 在 chebyshev (......) 的大作中提到: 】
: 如果有论文,应能对推广有正面作用。祝楼主成功。
: is

c
cstack

Yes, it relies on good testing. The downside is the coverage of testing will decide the coverage of bugs, the upside is there is no false positive,
which will consume developers time to work around.

【 在 dumbCoder (HumbleCoder 不懂就问-_-) 的大作中提到: 】
: "Only runtime checking. static analysis has too much false positives to my: liking."
: 只有 runtime checking 的话, 那内存错误检测(和错误信息)是要程序跑出错了才知道
: 了?
: 当然, 这样也很厉害了.
: none

d
dumbCoder

帮助很大了,比遇上segmentation fault后查core dump啥的强太多了

【 在 cstack (cstack) 的大作中提到: 】
: Yes, it relies on good testing. The downside is the coverage of testing
will
: decide the coverage of bugs, the upside is there is no false positive,
: which will consume developers time to work around.

d
dumbCoder

make sense

【 在 cstack (cstack) 的大作中提到: 】
: 有很大影响, 但是可支撑快速iterations, 能迅速找到memory bugs. 不一定适合于生
: 产部署.

T
TeacherWei

编译器要把每个memory access,也就是read/store都加上runtime check,检查边界
加类型。

慢,但是work。

p
pptwo

大概慢多少?Java号称慢1倍但在生产上算是很快了。

【 在 cstack (cstack) 的大作中提到: 】
: 有很大影响, 但是可支撑快速iterations, 能迅速找到memory bugs. 不一定适合于生
: 产部署.

s
sqrtn

这个不仅对教学,对开发人员的效率也是有巨大帮助的。可以商业化。为什么以前没人做,还是存在类似的工具只是没有公开?
s
sqrtn

这个不仅对教学,对开发人员的效率也是有巨大帮助的。可以商业化。为什么以前没人做,还是存在类似的工具只是没有公开?
g
guvest

支持楼主之工作与研究。
但是我认为:要快速开发,除了GC,别的办法很难成立。
上述论点有学理支持,也有历史事实做证据。
【 在 pptwo (pp) 的大作中提到: 】
: 大概慢多少?Java号称慢1倍但在生产上算是很快了。

T
TeacherWei

这个要慢好几倍。因为每个读写操作都要做检查,边界+类型,而且,这个检查导致执
行流水线很难优化。

只论性能,不可能超过Java和其他很多JIT编译器。所以楼主说C作为script语言我认为依然不合适。

但是,能够快速test C代码,也有巨大应用前景。当然,test case也是挑战。很多
buffer overrun之类的security vulnerability,不是测试困难,而是测试case都是在正常运行的条件下不能触发的。等到了产品级,优化编译了,就晚了。

【 在 pptwo (pp) 的大作中提到: 】
: 大概慢多少?Java号称慢1倍但在生产上算是很快了。

n
netghost

我不認爲生產環境帶着runtime checking對C是一個好主意。C的優勢就是結構簡單和性能。

測試環境當然是有好處的。

【 在 pptwo (pp) 的大作中提到: 】
: 大概慢多少?Java号称慢1倍但在生产上算是很快了。

g
guvest

c之标准有极多的undefine behavior。
仅考虑语法,似乎也不适合当作快速开发之script。

【 在 TeacherWei (TW) 的大作中提到: 】
: 这个要慢好几倍。因为每个读写操作都要做检查,边界+类型,而且,这个检查导致执
: 行流水线很难优化。
: 只论性能,不可能超过Java和其他很多JIT编译器。所以楼主说C作为script语言我认为
: 依然不合适。
: 但是,能够快速test C代码,也有巨大应用前景。当然,test case也是挑战。很多
: buffer overrun之类的security vulnerability,不是测试困难,而是测试case都是在
: 正常运行的条件下不能触发的。等到了产品级,优化编译了,就晚了。

n
netghost

你確定他的意思是用C當scripting語言?

我覺得他是指和別的scripting語言整合。
【 在 TeacherWei (TW) 的大作中提到: 】
: 这个要慢好几倍。因为每个读写操作都要做检查,边界+类型,而且,这个检查导致执
: 行流水线很难优化。
: 只论性能,不可能超过Java和其他很多JIT编译器。所以楼主说C作为script语言我认为
: 依然不合适。
: 但是,能够快速test C代码,也有巨大应用前景。当然,test case也是挑战。很多
: buffer overrun之类的security vulnerability,不是测试困难,而是测试case都是在
: 正常运行的条件下不能触发的。等到了产品级,优化编译了,就晚了。

g
guvest

python结合c/cpp已经事实上成功很久了。整合python+c/cpp这个办法,推
到别的应用领域,我觉得可以的。
【 在 netghost (Up to Isomorphism) 的大作中提到: 】
: 你確定他的意思是用C當scripting語言?
: 我覺得他是指和別的scripting語言整合。

n
netghost

python帶C基本上只能處理CPU/GPU bounded傻算的情況,i/o一進一出就完蛋了。

此外,python整合很麻煩,dependency亂飛,和C搞一起兩邊的優勢都沒了。這就是爲
啥有pip都不夠,還有anaconda這種東西原因:目的只爲了讓人裝上軟件。

【 在 guvest (我爱你老婆Anna) 的大作中提到: 】
: python结合c/cpp已经事实上成功很久了。整合python+c/cpp这个办法,推
: 到别的应用领域,我觉得可以的。

g
guvest

python社区之一大部分work就是把c/cpp各种库加个wrapper,
也包括各种i/o的c/cpp库。
【 在 netghost (Up to Isomorphism) 的大作中提到: 】
: python帶C基本上只能處理CPU/GPU bounded傻算的情況,i/o一進一出就完蛋了。
: 此外,python整合很麻煩,dependency亂飛,和C搞一起兩邊的優勢都沒了。這就是爲
: 啥有pip都不夠,還有anaconda這種東西原因:目的只爲了讓人裝上軟件。

n
netghost

性能慢,安裝麻煩,python混C是python handle不了性能只能找C幫忙。本質上是
python在白嫖C的優勢。

C要找個scripting enhance自己,最好的辦法肯定不是python。
【 在 guvest (我爱你老婆Anna) 的大作中提到: 】
: python社区之一大部分work就是把c/cpp各种库加个wrapper,
: 也包括各种i/o的c/cpp库。

C
Caravel

c不也可以用python完成高级编程。

【 在 netghost (Up to Isomorphism) 的大作中提到: 】
: 性能慢,安裝麻煩,python混C是python handle不了性能只能找C幫忙。本質上是
: python在白嫖C的優勢。
: C要找個scripting enhance自己,最好的辦法肯定不是python。

g
guvest

python就是白嫖界第一名。
【 在 netghost (Up to Isomorphism) 的大作中提到: 】
: 性能慢,安裝麻煩,python混C是python handle不了性能只能找C幫忙。本質上是
: python在白嫖C的優勢。
: C要找個scripting enhance自己,最好的辦法肯定不是python。

T
TeacherWei

重新读了一遍,他说:“我们现在在探索用纯C和嵌入式脚本engine做bot/webapp后台
开发”。

WebApp有个OpenResty,基于Nginx & Lua。其实是LuaJIT。

如果纯粹需要脚本,不考虑数学计算,Lua/LuaJIT依然是首选,比其他强太多。

我今年开始已经远离具体的嵌入式虚拟机了。我的做法是用TypeScript前端,
transpile成其它高级语言。有点非常多,首先,做个专用IDE是分分钟的事情。

【 在 netghost (Up to Isomorphism) 的大作中提到: 】
: 你確定他的意思是用C當scripting語言?
: 我覺得他是指和別的scripting語言整合。

c
cstack

是的, 但是可以优化
【 在 TeacherWei (TW) 的大作中提到: 】
: 编译器要把每个memory access,也就是read/store都加上runtime check,检查边界: 加类型。
: 慢,但是work。

c
cstack

没编译器优化:10-30 slow down.

C的写法不一样, 你可作cache locality, and memory allocation优化

生产部署在一情况下是可行的.
【 在 pptwo (pp) 的大作中提到: 】
: 大概慢多少?Java号称慢1倍但在生产上算是很快了。

c
cstack

We use embedded JavaScript.

【 在 TeacherWei (TW) 的大作中提到: 】
: 重新读了一遍,他说:“我们现在在探索用纯C和嵌入式脚本engine做bot/webapp后台
: 开发”。
: WebApp有个OpenResty,基于Nginx & Lua。其实是LuaJIT。
: 如果纯粹需要脚本,不考虑数学计算,Lua/LuaJIT依然是首选,比其他强太多。
: 我今年开始已经远离具体的嵌入式虚拟机了。我的做法是用TypeScript前端,
: transpile成其它高级语言。有点非常多,首先,做个专用IDE是分分钟的事情。

c
cstack

据我所知, 没有.

【 在 sqrtn (不问不行啊) 的大作中提到: 】
: 这个不仅对教学,对开发人员的效率也是有巨大帮助的。可以商业化。为什么以前没人
: 做,还是存在类似的工具只是没有公开?

i
igfx

这个对比的Clang版本有点老,不知道最新的Clang13的AddressSanitizer改进有多少。另外靠着LLVM,AddressSanitizer支持的平台多很多,社区也大很多。

【 在 cstack (cstack) 的大作中提到: 】
: https://www.cee.studio/comparison.html
: 我的可以保证runtime memory safety. All runtime memory errors can be
reported
: . (I submitted a POPL paper with proof. Unfortunately, it was not accepted,
: one reviewer recommended to submit to PLDI, I didn't bother with it).

m
mitbbs2715

这是做反了吧, 你要能把动态语言编译成高效率的C才有意义
【 在 cstack (cstack) 的大作中提到: 】
: 主页:https://www.cee.studio
: 它的优势: https://www.cee.studio/benefits.html
: Online IDE to test out: https://cee.studio
: 用C做的Discord库, https://github.com/cee-studio/orca
: 我们现在在探索用纯C和嵌入式脚本engine做bot/webapp后台开发. 希望和需要用C的公
: 司和或个人和作. 我是美国公民也可以接外包项目.
: 潜水多年,很是受益. 特别是netghost对C和其他语言的深刻见解