2Ju0
Ju0.log
2Ju0
전체 방문자
오늘
어제
  • 🐱‍🚀 모두보기 (32)
    • CS (18)
      • LLVM (11)
      • 운영체제 (1)
      • 보안 (3)
      • 프로그래밍언어 (0)
      • 데이터과학 (3)
    • PL (1)
      • Python (1)
      • JavaScript (0)
    • Algorithm (12)
      • Python (0)
      • Javascript (12)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

최근 댓글

최근 글

hELLO · Designed By 정상우.
2Ju0

Ju0.log

CS/LLVM

LLVM IR 비트코드 분석 - Array(배열)

2022. 4. 1. 12:41

array.c

#include <stdio.h>

int main() {
    int numArr[] = {1, 2, 3};
    int numArr2[3] = {1, 2, 3};
    int numArr3[3];
    numArr3[0] = 1;
    numArr3[1] = 2;
    numArr3[2] = 3;
}

array.ll

; Function Attrs: noinline nounwind optnone uwtable
define dso_local i32 @main() #0 {
entry:
  %numArr = alloca [3 x i32], align 4
  %numArr2 = alloca [3 x i32], align 4
  %numArr3 = alloca [3 x i32], align 4
  %0 = bitcast [3 x i32]* %numArr to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %0, i8* align 4 bitcast ([3 x i32]* @__const.main.numArr to i8*), i64 12, i1 false)
  %1 = bitcast [3 x i32]* %numArr2 to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %1, i8* align 4 bitcast ([3 x i32]* @__const.main.numArr2 to i8*), i64 12, i1 false)
  %arrayidx = getelementptr inbounds [3 x i32], [3 x i32]* %numArr3, i64 0, i64 0
  store i32 1, i32* %arrayidx, align 4
  %arrayidx1 = getelementptr inbounds [3 x i32], [3 x i32]* %numArr3, i64 0, i64 1
  store i32 2, i32* %arrayidx1, align 4
  %arrayidx2 = getelementptr inbounds [3 x i32], [3 x i32]* %numArr3, i64 0, i64 2
  store i32 3, i32* %arrayidx2, align 4
  ret i32 0
}

- i8: int 8비트

- @__const.main: ???

- memcpy: copy a block of memory from the source location to the destination location

- getelementptr: array element 가리키는 pointer getter

​

1) alloca로 로컬 변수 numArr 스택 메모리 할당

2) alloca로 로컬 변수 numArr2 스택 메모리 할당

3) alloca로 로컬 변수 numArr3 스택 메모리 할당

​

4) bitcast

5) bitcast를 위한 memcpy 함수 call

6)

7)

​

8) %arrayidx 변수에 numArr3의 0번 index 값을 가리키는 포인터를 담음

9) store로 로컬 변수 a 할당한 주소에 값 1 저장

​

10) %arrayidx 변수에 numArr3의 1번 index 값을 가리키는 포인터를 담음

11) store로 로컬 변수 a 할당한 주소에 값 2 저장

​

12) %arrayidx 변수에 numArr3의 2번 index 값을 가리키는 포인터를 담음

13)store로 로컬 변수 a 할당한 주소에 값 3 저장

​

14) return 0

    'CS/LLVM' 카테고리의 다른 글
    • LLVM IR 비트코드 분석 - malloc(말록)
    • LLVM IR 비트코드 분석 - Function(함수)
    • LLVM IR 비트코드 분석 - add(덧셈 연산)
    • LLVM IR 비트코드 분석 - Variable(변수)
    2Ju0
    2Ju0

    티스토리툴바